public void Remove(PayRequestDet PayRequestDet) { if (Context.Entry(PayRequestDet).State == EntityState.Detached) { context.PayRequestDets.Attach(PayRequestDet); } context.PayRequestDets.Remove(PayRequestDet); }
private List <Error> SaveGrid1(IEnumerable <PayRequestEmpsViewModel> grid1, IEnumerable <KeyValuePair <string, ModelState> > state, PayRequest payRequest) { List <Error> errors = new List <Error>(); if (ServerValidationEnabled) { var modified = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted"))); if (modified.Count > 0) { errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm { CompanyId = CompanyId, ObjectName = "PayRequestEmployees", Columns = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted"))), Culture = Language }); if (errors.Count() > 0) { return(errors); } } } var allRequestDets = _hrUnitOfWork.Repository <PayRequestDet>().Where(p => p.RequestId == payRequest.Id); var deleted = allRequestDets.Where(p => grid1.Where(i => i.EmpId == p.EmpId).Count() == 0).ToList(); foreach (PayRequestEmpsViewModel model in grid1) { PayRequestDet PayDet; if (model.Id == 0) // inserted records { PayDet = new PayRequestDet(); AutoMapper(new Models.AutoMapperParm { Destination = PayDet, Source = model, Transtype = TransType.Insert }); PayDet.Request = payRequest; _hrUnitOfWork.PayrollRepository.Add(PayDet); } else if (model.dirty) // updated records { PayDet = allRequestDets.Where(e => e.EmpId == model.EmpId).FirstOrDefault(); AutoMapper(new Models.AutoMapperParm { Destination = PayDet, Source = model, Transtype = TransType.Update }); _hrUnitOfWork.PayrollRepository.Attach(PayDet); _hrUnitOfWork.PayrollRepository.Entry(PayDet).State = EntityState.Modified; } } if (deleted.Count > 0) { foreach (PayRequestDet model in deleted) { _hrUnitOfWork.PayrollRepository.Remove(model); } } return(errors); }
public void Attach(PayRequestDet PayRequestDet) { context.PayRequestDets.Attach(PayRequestDet); }
public DbEntityEntry <PayRequestDet> Entry(PayRequestDet PayRequestDet) { return(Context.Entry(PayRequestDet)); }
public void Add(PayRequestDet PayRequestDet) { context.PayRequestDets.Add(PayRequestDet); }