public void Remove(DisplinRepeat period) { if (Context.Entry(period).State == EntityState.Detached) { context.DisplinRepeats.Attach(period); } context.DisplinRepeats.Remove(period); }
public DeciplineInfoViewModel GetDesplinInfo(string violdata, int desplinId, string culture) { DateTime dt = Convert.ToDateTime(violdata); var repeatObj = new DisplinRepeat(); var SuggestDisplin = new List <DisplinDLLViewModel>(); var result1 = (from d in context.Disciplines join p in context.DisplinPeriods on d.PeriodId equals p.Id join n in context.DisPeriodNo on p.Id equals n.PeriodId where n.PeriodSDate <= dt && n.PeriodEDate >= dt && n.Posted == false select new PeriodIDTypeViewModel { Id = d.Id, PeriodId = n.PeriodId, SysType = p.SysType, DisPeriodNOId = n.Id }).ToList(); var Actdisplin = context.DisplinRepeats.Where(a => a.DisplinId == desplinId).Select(a => new DisplinDLLViewModel { id = a.Id, name = a.Description, value = a.DisplinType }).ToList(); var record = result1.Where(s => s.SysType == 2 && s.Id == desplinId).FirstOrDefault(); var recordPoint = result1.Where(s => s.SysType == 1 && s.Id == desplinId).FirstOrDefault(); if (record != null) { int?periodId = record.PeriodId; var result2 = (from e in context.EmpDisciplines join d in context.Disciplines on e.DiscplinId equals d.Id join p in context.DisplinPeriods on d.PeriodId equals p.Id where p.Id == periodId select new PeriodIDTypeViewModel { PeriodId = d.PeriodId }).ToList().Count(); var repNo = result2 + 1; var Repnum = context.DisplinRepeats.Max(a => a.RepNo); repeatObj = context.DisplinRepeats.Where(s => s.RepNo == repNo && s.DisplinId == desplinId).FirstOrDefault(); SuggestDisplin = context.DisplinRepeats.Where(a => a.DisplinId == desplinId && a.RepNo == repNo).Select(a => new DisplinDLLViewModel { id = a.Id, name = HrContext.GetLookUpUserCode("DisplinType", a.DisplinType, culture) }).ToList(); if (repeatObj == null) { repeatObj = context.DisplinRepeats.Where(s => s.RepNo == Repnum && s.DisplinId == desplinId).FirstOrDefault(); SuggestDisplin = context.DisplinRepeats.Where(a => a.DisplinId == desplinId && a.RepNo == Repnum).Select(a => new DisplinDLLViewModel { id = a.Id, name = HrContext.GetLookUpUserCode("DisplinType", a.DisplinType, culture) }).ToList(); } } DeciplineInfoViewModel disInfo = new DeciplineInfoViewModel { periodmodel = record, periodPoint = recordPoint, ReapetObj = repeatObj, ActDisplinDDl = Actdisplin, SuggDisplinDDl = SuggestDisplin }; return(disInfo); }
private List <Error> SaveGrid1(RequestDisplinRepeatGrid grid1, IEnumerable <KeyValuePair <string, ModelState> > state, Discipline Displinobj) { List <Error> errors = new List <Error>(); // Deleted if (grid1.deleted != null) { foreach (DisplinRepeatViewModel model in grid1.deleted) { var RequestDisplinRepeat = new DisplinRepeat { Id = model.Id }; _hrUnitOfWork.DisciplineRepository.Remove(RequestDisplinRepeat); } } // Exclude delete models from sever side validations 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 = "DisplinRepeats", Columns = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted"))), Culture = Language }); if (errors.Count() > 0) { return(errors); } } } // updated records if (grid1.updated != null) { foreach (DisplinRepeatViewModel model in grid1.updated) { var requestRe = new DisplinRepeat(); AutoMapper(new Models.AutoMapperParm { Destination = requestRe, Source = model }); requestRe.ModifiedTime = DateTime.Now; requestRe.ModifiedUser = UserName; _hrUnitOfWork.DisciplineRepository.Attach(requestRe); _hrUnitOfWork.DisciplineRepository.Entry(requestRe).State = EntityState.Modified; } } // inserted records if (grid1.inserted != null) { foreach (DisplinRepeatViewModel model in grid1.inserted) { var requestRe = new DisplinRepeat(); AutoMapper(new Models.AutoMapperParm { Destination = requestRe, Source = model }); requestRe.Discipline = Displinobj; requestRe.CreatedTime = DateTime.Now; requestRe.CreatedUser = UserName; _hrUnitOfWork.DisciplineRepository.Add(requestRe); } } return(errors); }
public DbEntityEntry <DisplinRepeat> Entry(DisplinRepeat period) { return(Context.Entry(period)); }
public void Attach(DisplinRepeat period) { context.DisplinRepeats.Attach(period); }
public void Add(DisplinRepeat period) { context.DisplinRepeats.Add(period); }