public ActionResult EmployeeMessagesDelete(int Id) { var Message = "OK"; var EmpMess = _hrUnitOfWork.MessageRepository.GetEmpMessage(Id); if (EmpMess != null) { _hrUnitOfWork.MessageRepository.Remove(EmpMess); } try { var err = SaveChanges(Language); if (err.Count() > 0) { foreach (var item in err) { Message = item.errors.Select(a => a.message).FirstOrDefault(); } return(Json(Message, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg, JsonRequestBehavior.AllowGet)); } } return(Json(Message, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult deleteMessage(int Id) { var Message = "Ok"; var EmpMess = _hrUnitOfWork.MessageRepository.GetEmpMessage(Id); if (EmpMess != null) { _hrUnitOfWork.MessageRepository.Remove(EmpMess); } try { var err = SaveChanges(User.Identity.GetLanguage()); if (err.Count() > 0) { foreach (var item in err) { Message = item.errors.Select(a => a.message).FirstOrDefault(); } return(Ok(Message)); } } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, User.Identity.GetLanguage()); if (msg.Length > 0) { return(Ok(msg)); } } return(Ok(Message)); }
public ActionResult Delete(string Sort) { var Message = "OK"; var list = _hrUnitOfWork.Repository <Menu>().Where(a => a.CompanyId == CompanyId && a.Sort.StartsWith(Sort)).ToList(); var ids = list.Select(a => a.Id); var pages = _hrUnitOfWork.Repository <PageDiv>().Where(a => a.CompanyId == CompanyId && ids.Contains(a.MenuId) && a.Version > 0); if (pages != null) { var titles = _hrUnitOfWork.PagesRepository.GetColumnTitles(CompanyId, ids); if (titles != null) { _hrUnitOfWork.PagesRepository.RemoveRange(titles); } _hrUnitOfWork.PagesRepository.RemoveRange(pages); } _hrUnitOfWork.MenuRepository.RemoveRange(list); try { var err = SaveChanges(Language); if (err.Count() > 0) { foreach (var item in err) { Message = item.errors.Select(a => a.message).FirstOrDefault(); } return(Json(Message, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg, JsonRequestBehavior.AllowGet)); } } return(Json(Message, JsonRequestBehavior.AllowGet)); }
public ActionResult TermFollowUpDetails(TerminationFormViewModel model, OptionsViewModel moreInfo) { List <Error> errors = new List <Error>(); var Term = _hrUnitOfWork.TerminationRepository.Get(model.Id); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.TerminationRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "EmpTermFollowUp", TableName = "Terminations", Columns = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))), ParentColumn = "CompanyId", 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))); } } } else { return(Json(Models.Utils.ParseFormErrors(ModelState))); } if (model.ApprovalStatus != 9) { model.RejectDesc = null; model.RejectReason = null; } if (model.ApprovalStatus != 5) { model.ActualDate = null; } AutoMapper(new Models.AutoMapperParm { Destination = Term, Source = model, ObjectName = "EmpTermFollowUp", Options = moreInfo, Transtype = TransType.Update }); Term.ModifiedTime = DateTime.Now; Term.ModifiedUser = UserName; if (Term.ApprovalStatus == 5 || Term.ApprovalStatus == 6) //Accept or Rejected { string error = AddWFTrans(Term, null, null); if (error.Length > 0) { return(Json(error)); } } _hrUnitOfWork.TerminationRepository.Attach(Term); _hrUnitOfWork.TerminationRepository.Entry(Term).State = EntityState.Modified; try { _hrUnitOfWork.Save(); } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg)); } } return(Json("OK")); }
public ActionResult SaveSalaryVar(SalaryVarFormViewModel model, OptionsViewModel moreInfo, SalaryEmpVarGridViewModel grid1) { List <Error> errors = new List <Error>(); var SalaryVarRecord = _hrUnitOfWork.PayrollRepository.GetSalVar(model.Reference); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.PositionRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "SalaryVar", TableName = "SalaryVars", Columns = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))), ParentColumn = "PayPeriodId", 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))); } } } else { return(Json(Models.Utils.ParseFormErrors(ModelState))); } var multi = _hrUnitOfWork.Repository <SalaryItem>().Where(a => a.Id == model.SalItemId).Select(a => a.Multiple).FirstOrDefault(); List <SalaryVar> ListOfSalaryVar = new List <SalaryVar>(); if (SalaryVarRecord == null) // New { if (grid1.inserted != null) { Guid newGUID = Guid.NewGuid(); foreach (var item in grid1.inserted) { SalaryVarRecord = new SalaryVar(); SalaryVarRecord.Approvedby = UserName; SalaryVarRecord.Curr = model.Curr; SalaryVarRecord.PayPeriodId = model.PayPeriodId; SalaryVarRecord.PayrollId = model.PayrollId; SalaryVarRecord.SalItemId = model.SalItemId; SalaryVarRecord.CreatedTime = DateTime.Now; SalaryVarRecord.CreatedUser = UserName; SalaryVarRecord.Reference = newGUID; SalaryVarRecord.EmpId = item.EmpId; SalaryVarRecord.Amount = item.Amount; SalaryVarRecord.Status = item.Status; ListOfSalaryVar.Add(SalaryVarRecord); } _hrUnitOfWork.PayrollRepository.AddRange(ListOfSalaryVar); if (multi == false) { var empIds = ListOfSalaryVar.Select(a => a.EmpId).ToList(); if (empIds.Count != empIds.Distinct().Count()) { ModelState.AddModelError("", MsgUtils.Instance.Trls("CantAcceptMultiInPeriod")); return(Json(Models.Utils.ParseFormErrors(ModelState))); } } } else { SalaryVarRecord = new SalaryVar(); AutoMapper(new Models.AutoMapperParm { Destination = SalaryVarRecord, Source = model, ObjectName = "SalaryVar", Options = moreInfo }); _hrUnitOfWork.PayrollRepository.Add(SalaryVarRecord); } } else // Edit { //if form is updated only if (grid1.inserted == null && grid1.updated == null) { var listOfSalaryVar = _hrUnitOfWork.Repository <SalaryVar>().Where(a => a.Reference == model.Reference).ToList(); foreach (var salary in listOfSalaryVar) { AutoMapper(new Models.AutoMapperParm { Destination = salary, Source = model, ObjectName = "SalaryVar", Options = moreInfo, Transtype = TransType.Update }); SalaryVarRecord.ModifiedTime = DateTime.Now; SalaryVarRecord.ModifiedUser = UserName; _hrUnitOfWork.PayrollRepository.Attach(SalaryVarRecord); _hrUnitOfWork.PayrollRepository.Entry(SalaryVarRecord).State = EntityState.Modified; } } // if insert in grid if (grid1.inserted != null) { foreach (var item in grid1.inserted) { SalaryVarRecord = new SalaryVar(); SalaryVarRecord.Approvedby = UserName; SalaryVarRecord.Curr = model.Curr; SalaryVarRecord.PayPeriodId = model.PayPeriodId; SalaryVarRecord.PayrollId = model.PayrollId; SalaryVarRecord.SalItemId = model.SalItemId; SalaryVarRecord.CreatedTime = DateTime.Now; SalaryVarRecord.CreatedUser = UserName; SalaryVarRecord.Reference = model.Reference; SalaryVarRecord.EmpId = item.EmpId; SalaryVarRecord.Amount = item.Amount; SalaryVarRecord.Status = item.Status; ListOfSalaryVar.Add(SalaryVarRecord); } _hrUnitOfWork.PayrollRepository.AddRange(ListOfSalaryVar); if (multi == false) { var dbEmpIds = _hrUnitOfWork.Repository <SalaryVar>().Where(a => a.Reference == model.Reference).Select(s => s.EmpId).ToList(); var empIds = ListOfSalaryVar.Select(a => a.EmpId).ToList(); List <int> chkList = new List <int>(); chkList.AddRange(dbEmpIds); chkList.AddRange(empIds); if (chkList.Count != chkList.Distinct().Count()) { ModelState.AddModelError("", MsgUtils.Instance.Trls("CantAcceptMultiInPeriod")); return(Json(Models.Utils.ParseFormErrors(ModelState))); } } } //if update in grid and form if (grid1.updated != null) { foreach (var item in grid1.updated) { SalaryVarRecord = _hrUnitOfWork.Repository <SalaryVar>().Where(a => a.Id == item.Id).FirstOrDefault(); SalaryVarRecord.Approvedby = UserName; SalaryVarRecord.Curr = model.Curr; SalaryVarRecord.PayPeriodId = model.PayPeriodId; SalaryVarRecord.PayrollId = model.PayrollId; SalaryVarRecord.SalItemId = model.SalItemId; SalaryVarRecord.ModifiedTime = DateTime.Now; SalaryVarRecord.ModifiedUser = UserName; SalaryVarRecord.Reference = model.Reference; SalaryVarRecord.EmpId = item.EmpId; SalaryVarRecord.Amount = item.Amount; SalaryVarRecord.Status = item.Status; _hrUnitOfWork.PayrollRepository.Attach(SalaryVarRecord); _hrUnitOfWork.PayrollRepository.Entry(SalaryVarRecord).State = EntityState.Modified; } } if (grid1.deleted != null) { foreach (var item in grid1.deleted) { SalaryVarRecord = _hrUnitOfWork.Repository <SalaryVar>().Where(a => a.Id == item.Id).FirstOrDefault(); SalaryVarRecord.Status = 2; _hrUnitOfWork.PayrollRepository.Attach(SalaryVarRecord); _hrUnitOfWork.PayrollRepository.Entry(SalaryVarRecord).State = EntityState.Modified; } } if (model.submit == true) { var listOfSalary = _hrUnitOfWork.Repository <SalaryVar>().Where(a => a.Reference == model.Reference && a.Status == 0).ToList(); if (listOfSalary.Count() > 0) { for (int i = 0; i < listOfSalary.Count; i++) { listOfSalary[i].Status = 1; _hrUnitOfWork.PayrollRepository.Attach(listOfSalary[i]); _hrUnitOfWork.PayrollRepository.Entry(listOfSalary[i]).State = EntityState.Modified; } } } } if (errors.Count > 0) { return(Json(errors.First().errors.First().message)); } try { _hrUnitOfWork.Save(); } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg)); } } return(Json("OK," + ((new JavaScriptSerializer()).Serialize(SalaryVarRecord)))); }
public ActionResult SaveDiagram(Diagram NewDiagram, IList <DiagramNode> DiagramNodes, OptionsViewModel moreInfo) { List <int> newnodes = new List <int>(); for (int i = 0; i < DiagramNodes.Count; i++) { if (!DiagramNodes.Select(a => a.ChildId).Contains(DiagramNodes[i].ParentId)) { newnodes.Add(DiagramNodes[i].ParentId); } } foreach (var item in newnodes.Distinct()) { DiagramNode node = new DiagramNode() { ParentId = 0, ChildId = item, DiagramId = DiagramNodes[0].DiagramId }; DiagramNodes.Add(node); } Diagram dd = _hrUnitOfWork.Repository <Diagram>().Where(a => a.Id == NewDiagram.Id).FirstOrDefault(); if (dd != null) { if (NewDiagram.Name != null) { dd.Color = NewDiagram.Color; dd.EndDate = NewDiagram.EndDate; dd.Name = NewDiagram.Name; dd.StartDate = NewDiagram.StartDate; dd.CompanyId = CompanyId; dd.ModifiedTime = DateTime.Now; dd.ModifiedUser = UserName; _hrUnitOfWork.PositionRepository.Attach(dd); _hrUnitOfWork.PositionRepository.Entry(dd).State = EntityState.Modified; } var ndi = _hrUnitOfWork.Repository <DiagramNode>().Where(a => a.DiagramId == dd.Id).Select(b => b); foreach (var item in ndi) { _hrUnitOfWork.PositionRepository.Remove(item); } } else { dd = new Diagram(); dd.Color = NewDiagram.Color; dd.EndDate = NewDiagram.EndDate; dd.Name = NewDiagram.Name; dd.StartDate = NewDiagram.StartDate; dd.CompanyId = CompanyId; dd.CreatedTime = DateTime.Now; dd.CreatedUser = UserName; _hrUnitOfWork.PositionRepository.Add(dd); } for (int i = 0; i < DiagramNodes.Count; i++) { DiagramNode di = new DiagramNode() { DiagramId = dd.Id, ChildId = DiagramNodes[i].ChildId, ParentId = DiagramNodes[i].ParentId }; _hrUnitOfWork.PositionRepository.Add(di); } try { _hrUnitOfWork.Save(); } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg)); } } return(Json("Ok," + dd.Id)); }
public IHttpActionResult SaveTermination(TerminationFormViewModel model) { List <Model.ViewModel.Error> errors = new List <Model.ViewModel.Error>(); if (!ModelState.IsValid) { return(Json(Utils.ParseFormError(ModelState))); } string message = "Ok"; model.EmpId = User.Identity.GetEmpId(); model.EmpId = 1042; var Term = _hrUnitOfWork.TerminationRepository.Get(model.Id); if (Term == null) // New { Term = new Termination(); AutoMapperParm parms = new AutoMapperParm() { Source = model, Destination = Term }; AutoMapper(parms); Term.CreatedTime = DateTime.Now; Term.CreatedUser = User.Identity.Name; Term.RequestDate = DateTime.Now; if (model.Excute) { Term.ApprovalStatus = 2; } _hrUnitOfWork.TerminationRepository.Add(Term); } else // Edit { AutoMapperParm parms = new AutoMapperParm() { Source = model, Destination = Term }; AutoMapper(parms); Term.ModifiedTime = DateTime.Now; Term.ModifiedUser = User.Identity.Name; if (model.Excute) { Term.ApprovalStatus = 2; } _hrUnitOfWork.TerminationRepository.Attach(Term); _hrUnitOfWork.TerminationRepository.Entry(Term).State = EntityState.Modified; } if (model.Excute) { string error = AddWFTrans(Term, null, null); if (error.Length > 0) { return(Json(error)); } var checklist = _hrUnitOfWork.CheckListRepository.GetTermCheckLists(User.Identity.GetDefaultCompany()); if (checklist != null) { EmpChkList EmpList = _hrUnitOfWork.CheckListRepository.AddEmpChlst(checklist, User.Identity.Name, Term.EmpId, User.Identity.GetDefaultCompany()); _hrUnitOfWork.CheckListRepository.Add(EmpList); var checkTask = _hrUnitOfWork.CheckListRepository.ReadCheckListTask(checklist.Id).ToList(); if (checkTask.Count > 0) { _hrUnitOfWork.CheckListRepository.AddEmpTask(checkTask, User.Identity.Name, EmpList); } } } try { _hrUnitOfWork.Save(); } catch (Exception ex) { message = _hrUnitOfWork.HandleDbExceptions(ex, User.Identity.GetLanguage()); if (message.Length > 0) { return(Ok(message)); } } return(Ok(message)); }
public ActionResult Details(CompanyFormViewModel model, OptionsViewModel moreInfo) //, System.Web.HttpPostedFileBase upload { List <Error> errors = new List <Error>(); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.CompanyRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "Company", TableName = "Companies", 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))); } } } else { return(Json(Models.Utils.ParseFormErrors(ModelState))); } Model.Domain.Company record; //var Sequence = _hrUnitOfWork.Repository<Model.Domain.Company>().Select(a => a.Code).DefaultIfEmpty(0).Max(); //var MaxCode = Sequence == 0 ? 1 : Sequence + 1; var edit = Request.QueryString["edit"]; if (model.Id == -1) // New { record = new Model.Domain.Company(); AutoMapper(new Models.AutoMapperParm { Destination = record, Source = model, ObjectName = "Company", Options = moreInfo, Transtype = TransType.Insert }); record.CreatedUser = UserName; record.CreatedTime = DateTime.Now; // record.Code = MaxCode; _hrUnitOfWork.CompanyRepository.AddLName(Language, record.Name, model.Name, model.LocalName); _hrUnitOfWork.PagesRepository.AddCompany(record); } else // Edit { record = _hrUnitOfWork.Repository <Model.Domain.Company>().FirstOrDefault(a => a.Id == model.Id); AutoMapper(new Models.AutoMapperParm { Destination = record, Source = model, ObjectName = "Company", Options = moreInfo, Transtype = TransType.Update }); record.ModifiedTime = DateTime.Now; record.ModifiedUser = UserName; _hrUnitOfWork.CompanyRepository.AddLName(Language, record.Name, model.Name, model.LocalName); _hrUnitOfWork.CompanyRepository.Attach(record); _hrUnitOfWork.CompanyRepository.Entry(record).State = EntityState.Modified; } try { _hrUnitOfWork.Save(); } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg)); } } var savedCompany = _hrUnitOfWork.Repository <Model.Domain.Company>().FirstOrDefault(c => c.Name == model.Name); string message = "OK," + (new JavaScriptSerializer().Serialize(savedCompany)); return(Json(message)); }
public ActionResult Details(CompanyStructureViewModel model, OptionsViewModel moreInfo) { var Message = "OK"; List <Error> errors = new List <Error>(); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.CompanyStructureRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "CompanyStructure", TableName = "CompanyStructures", Columns = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))), ParentColumn = "CompanyId", 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))); } } } else { return(Json(Models.Utils.ParseFormErrors(ModelState))); } CompanyStructure compStruc; if (model.Id == 0) // New { compStruc = new CompanyStructure(); _hrUnitOfWork.PositionRepository.AddLName(Language, compStruc.Name, model.Name, model.LocalName); AutoMapper(new Models.AutoMapperParm { Destination = compStruc, Source = model, ObjectName = "CompanyStructure", Options = moreInfo, Transtype = TransType.Insert }); compStruc.CompanyId = CompanyId; compStruc.CreatedTime = DateTime.Now; compStruc.CreatedUser = UserName; _hrUnitOfWork.CompanyStructureRepository.Add(compStruc); } else // Edit { compStruc = _hrUnitOfWork.Repository <CompanyStructure>().Where(a => a.Id == model.Id).FirstOrDefault(); _hrUnitOfWork.PositionRepository.AddLName(Language, compStruc.Name, model.Name, model.LocalName); AutoMapper(new Models.AutoMapperParm { Destination = compStruc, Source = model, ObjectName = "CompanyStructure", Version = 0, Options = moreInfo, Transtype = TransType.Update }); compStruc.ModifiedTime = DateTime.Now; compStruc.ModifiedUser = UserName; _hrUnitOfWork.CompanyStructureRepository.Attach(compStruc); _hrUnitOfWork.CompanyStructureRepository.Entry(compStruc).State = EntityState.Modified; } try { var err = SaveChanges(Language); if (err.Count() > 0) { foreach (var item in err) { Message = item.errors.Select(a => a.message).FirstOrDefault(); } return(Json(Message)); } } catch (Exception ex) { var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language); if (msg.Length > 0) { return(Json(msg)); } } return(Json(Message)); }