public void Create(DonorGivingModel donorGiving) { if (!UpdateDatabase) { var first = GetAll().OrderByDescending(e => e.DonorGivingID).FirstOrDefault(); var id = (first != null) ? first.DonorGivingID : 0; GetAll().Insert(0, donorGiving); } else { var entity = new DonorGiving(); entity.DonorGivingID = donorGiving.DonorGivingID; entity.DonorID = donorGiving.DonorID; entity.AmountGiven = donorGiving.AmountGiven; entity.DateGiven = donorGiving.DateGiven; entity.InKind = donorGiving.InKind; entity.IsDeleted = donorGiving.IsDeleted; entities.DonorGivings.Add(entity); entities.SaveChanges(); donorGiving.DonorGivingID = entity.DonorGivingID; } }
public void Update(DonorGivingModel donorGiving) { if (!UpdateDatabase) { var target = One(e => e.DonorGivingID == donorGiving.DonorGivingID); if (target != null) { target.DonorGivingID = donorGiving.DonorGivingID; target.DonorID = donorGiving.DonorID; target.AmountGiven = donorGiving.AmountGiven; target.DateGiven = donorGiving.DateGiven; target.InKind = donorGiving.InKind; target.IsDeleted = donorGiving.IsDeleted; } } else { var entity = new DonorGiving(); entity.DonorGivingID = donorGiving.DonorGivingID; entity.DonorID = donorGiving.DonorID; entity.AmountGiven = donorGiving.AmountGiven; entity.DateGiven = donorGiving.DateGiven; entity.InKind = donorGiving.InKind; entity.IsDeleted = donorGiving.IsDeleted; entities.DonorGivings.Attach(entity); entities.Entry(entity).State = EntityState.Modified; entities.SaveChanges(); } }
public void Destroy(DonorGivingModel donorGiving) { if (!UpdateDatabase) { var target = GetAll().FirstOrDefault(p => p.DonorGivingID == donorGiving.DonorGivingID); if (target != null) { GetAll().Remove(target); } } else { var target = (from s in entities.DonorGivings where s.DonorGivingID == donorGiving.DonorGivingID select s).FirstOrDefault(); if (target != null) { target.IsDeleted = true; entities.Entry(target).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); } } }