public GetCreateMsOfficerListDto CreateMsOfficer(CreateMsOfficerInput input) { Logger.Info("CreateMsOfficer() - Started."); var data = new MS_Officer { officerName = input.officerName, officerEmail = input.email, officerPhone = input.handphone, departmentID = input.departmentID, positionID = input.positionID, isActive = input.isActive }; try { Logger.DebugFormat("CreateMsOfficer() - Start insert Officer. Parameters sent:{0}" + "officerName = {1}{0}" + "officerEmail = {2}{0}" + "officerPhone = {3}{0}" + "departmentID = {4}{0}" + "positionID = {5}{0}" + "isActive = {6}{0}" , Environment.NewLine, input.officerName, input.email, input.handphone, input.departmentID , input.positionID, input.isActive); int id = _msOfficerRepo.InsertAndGetId(data); CurrentUnitOfWork.SaveChanges(); Logger.DebugFormat("CreateMsOfficer() - Ended insert Officer."); var dataReturn = (from A in _msOfficerRepo.GetAll() join B in _msDepartmentRepo.GetAll() on A.departmentID equals B.Id where A.Id == id select new GetCreateMsOfficerListDto { officerID = id, departmentName = B.departmentName, departmentID = B.Id }).FirstOrDefault(); Logger.Info("CreateMsOfficer() - Finished."); return(dataReturn); } catch (DataException ex) { Logger.ErrorFormat("CreateMsOfficer() - ERROR DataException. Result = {0}", ex.Message); throw new UserFriendlyException("Db Error: " + ex.Message); } catch (Exception ex) { Logger.ErrorFormat("CreateMsOfficer() - ERROR Exception. Result = {0}", ex.Message); throw new UserFriendlyException("Error: " + ex.Message); } }
public JObject UpdateMsOfficer(CreateMsOfficerInput input) { JObject obj = new JObject(); Logger.Info("UpdateMsOfficer() - Started."); Logger.DebugFormat("UpdateMsOfficer() - Start get data before update Officer. Parameters sent:{0}" + "officerID = {1}{0}" , Environment.NewLine, input.id); var checkProject = _msProjectRepo.GetAll().Where(x => x.SADStaffID == input.id || x.SADManagerID == input.id || x.PGStaffID == input.id || x.SADBMID == input.id || x.bankRelationManagerID == input.id || x.bankRelationStaffID == input.id || x.callCenterManagerID == input.id || x.callCenterStaffID == input.id || x.financeManagerID == input.id || x.financeStaffID == input.id).Any(); var getMsOfficer = (from a in _msOfficerRepo.GetAll() where a.Id == input.id select a).FirstOrDefault(); var updateMsOfficer = getMsOfficer.MapTo <MS_Officer>(); updateMsOfficer.officerEmail = input.email; updateMsOfficer.officerPhone = input.handphone; updateMsOfficer.isActive = input.isActive; if (!checkProject) { updateMsOfficer.officerName = input.officerName; updateMsOfficer.positionID = input.positionID; updateMsOfficer.departmentID = input.departmentID; obj.Add("message", "Edit Successfully"); } else { obj.Add("message", "Edit Successfully, but can't change Name, Department & Position"); } Logger.Info("UpdateMsOfficer() - Finished."); return(obj); }