public TrainPathFormViewModel ReadTrainPath(int Id, string culture) { var obj = context.TrainPath.Where(a => a.Id == Id).Select(a => new { a, LocalName = HrContext.TrlsName(a.Name, culture) }).FirstOrDefault(); var mod = new TrainPathFormViewModel() { Id = obj.a.Id, Name = obj.a.Name, StartDate = obj.a.StartDate, Summary = obj.a.Summary, IsLocal = obj.a.IsLocal, Age = obj.a.Age, EndDate = obj.a.EndDate, Formula = obj.a.Formula, Performance = obj.a.Performance, YearServ = obj.a.YearServ, Qualification = obj.a.Qualification, LocalName = obj.LocalName, QualRank = obj.a.QualRank, CreatedTime = obj.a.CreatedTime, CreatedUser = obj.a.CreatedUser, ModifiedTime = obj.a.ModifiedTime, ModifiedUser = obj.a.ModifiedUser, IPayrolls = obj.a.Payrolls == null ? null : obj.a.Payrolls.Split(',').Select(int.Parse).ToList(), ICompanyStuctures = obj.a.CompanyStuctures == null ? null : obj.a.CompanyStuctures.Split(',').Select(int.Parse).ToList(), IEmployments = obj.a.Employments == null ? null : obj.a.Employments.Split(',').Select(int.Parse).ToList(), IPayrollGrades = obj.a.PayrollGrades == null ? null : obj.a.PayrollGrades.Split(',').Select(int.Parse).ToList(), IPositions = obj.a.Positions == null ? null : obj.a.Positions.Split(',').Select(int.Parse).ToList(), IBranches = obj.a.Branches == null ? null : obj.a.Branches.Split(',').Select(int.Parse).ToList(), IJobs = obj.a.Jobs == null ? null : obj.a.Jobs.Split(',').Select(int.Parse).ToList(), IPeopleGroups = obj.a.PeopleGroups == null ? null : obj.a.PeopleGroups.Split(',').Select(int.Parse).ToList() }; return(mod); }
private void MapTrainPath(TrainPath trainPath, TrainPathFormViewModel model, OptionsViewModel moreInfo) { model.Branches = model.IBranches == null ? null : string.Join(",", model.IBranches.ToArray()); model.Jobs = model.IJobs == null ? null : string.Join(",", model.IJobs.ToArray()); model.Employments = model.IEmployments == null ? null : string.Join(",", model.IEmployments.ToArray()); model.PeopleGroups = model.IPeopleGroups == null ? null : string.Join(",", model.IPeopleGroups.ToArray()); model.Payrolls = model.IPayrolls == null ? null : string.Join(",", model.IPayrolls.ToArray()); model.PayrollGrades = model.IPayrollGrades == null ? null : string.Join(",", model.IPayrollGrades.ToArray()); model.CompanyStuctures = model.ICompanyStuctures == null ? null : string.Join(",", model.ICompanyStuctures.ToArray()); model.Positions = model.IPositions == null ? null : string.Join(",", model.IPositions.ToArray()); moreInfo.VisibleColumns.Add("Branches"); moreInfo.VisibleColumns.Add("Jobs"); moreInfo.VisibleColumns.Add("Employments"); moreInfo.VisibleColumns.Add("PeopleGroups"); moreInfo.VisibleColumns.Add("Payrolls"); moreInfo.VisibleColumns.Add("PayrollGrades"); moreInfo.VisibleColumns.Add("CompanyStuctures"); moreInfo.VisibleColumns.Add("Positions"); _hrUnitOfWork.LeaveRepository.AddLName(Language, trainPath.Name, model.Name, model.LocalName); if (trainPath.Id == 0) { AutoMapper(new Models.AutoMapperParm { Destination = trainPath, Source = model, ObjectName = "TrainPath", Options = moreInfo, Transtype = TransType.Insert }); } else { AutoMapper(new Models.AutoMapperParm { Destination = trainPath, Source = model, ObjectName = "TrainPath", Options = moreInfo, Transtype = TransType.Update }); } }
public ActionResult DetailsTrainPath(TrainPathFormViewModel model, OptionsViewModel moreInfo) { List <Error> errors = new List <Error>(); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "TrainPath", TableName = "TrainPaths", Columns = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))), Culture = Language }); if (errors.Count() > 0) { foreach (var e in errors) { foreach (var errorMsg in e.errors) { ModelState.AddModelError(errorMsg.field, errorMsg.message); } } return(Json(Models.Utils.ParseFormErrors(ModelState))); } } var record = _hrUnitOfWork.Repository <TrainPath>().FirstOrDefault(a => a.Id == model.Id); //insert if (record == null) { record = new TrainPath(); MapTrainPath(record, model, moreInfo); record.CreatedUser = UserName; record.CreatedTime = DateTime.Now; record.CompanyId = model.IsLocal ? CompanyId : (int?)null; if (record.StartDate > record.EndDate) { ModelState.AddModelError("EndDate", MsgUtils.Instance.Trls("EndDateGthanStartDate")); return(Json(Models.Utils.ParseFormErrors(ModelState))); } _hrUnitOfWork.TrainingRepository.Add(record); } //update else { MapTrainPath(record, model, moreInfo); record.ModifiedTime = DateTime.Now; record.ModifiedUser = UserName; record.CompanyId = model.IsLocal ? CompanyId : (int?)null; if (record.StartDate > record.EndDate) { ModelState.AddModelError("EndDate", MsgUtils.Instance.Trls("EndDateGthanStartDate")); return(Json(Models.Utils.ParseFormErrors(ModelState))); } _hrUnitOfWork.TrainingRepository.Attach(record); _hrUnitOfWork.TrainingRepository.Entry(record).State = EntityState.Modified; } var Errors = SaveChanges(Language); TempData["pathId"] = record.Id; var message = "OK"; if (Errors.Count > 0) { message = Errors.First().errors.First().message; } return(Json(message)); } return(Json(Models.Utils.ParseFormErrors(ModelState))); }