61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using Weee.DAL;
|
|
using Weee.Models;
|
|
|
|
namespace Weee.Service
|
|
{
|
|
public class IntlTravelDataService : WeeeLCADataService
|
|
{
|
|
public IntlTravelDataService(WeeeDataContext db)
|
|
: base(db)
|
|
{
|
|
}
|
|
|
|
public IQueryable<LCARiskAssmtSurveyForm_IntlTravel> GetList(int LCAID)
|
|
{
|
|
if (!AuthorizedLCAs.Contains(LCAID)) throw new Exception("not authorized");
|
|
return _db.Set<LCARiskAssmtSurveyForm_IntlTravel>().Where(x => x.LCAID == LCAID)
|
|
.OrderByDescending(x => x.ID);
|
|
}
|
|
|
|
public LCARiskAssmtSurveyForm_IntlTravel Save(LCARiskAssmtSurveyForm_IntlTravel toBeSave)
|
|
{
|
|
var user = GetUserContext();
|
|
|
|
if (!AuthorizedLCAs.Contains(toBeSave.LCAID)) throw new Exception("not authorized");
|
|
var entry = _db.Entry(toBeSave);
|
|
if (toBeSave.ID == 0)
|
|
{
|
|
toBeSave.CreatedBy = user.Id;
|
|
toBeSave.CreatedDate = DateTime.Now;
|
|
entry.State = EntityState.Added;
|
|
}
|
|
else
|
|
{
|
|
toBeSave.ModifiedBy = user.Id;
|
|
toBeSave.ModifiedDate = DateTime.Now;
|
|
entry.State = EntityState.Modified;
|
|
entry.Property(x => x.LCAID).IsModified = false;
|
|
}
|
|
|
|
_db.SaveChanges();
|
|
return toBeSave;
|
|
}
|
|
|
|
public void Delete(int ID)
|
|
{
|
|
var entry = _db.Set<LCARiskAssmtSurveyForm_IntlTravel>().Where(x => x.ID == ID).Single();
|
|
var LCA = GetLCA(entry.LCAID);
|
|
if (LCA.Status != LCAStatus.New && LCA.Status != LCAStatus.Processing) throw new Exception("Business logic error , should not delete data in this status: " + LCA.Status.ToString());
|
|
|
|
var ToBeDelete = _db.Entry(entry);
|
|
ToBeDelete.State = EntityState.Deleted;
|
|
|
|
_db.SaveChanges();
|
|
}
|
|
}
|
|
} |