public int UpdateAdminSetting(AdministratorSettingModel model) { var administratorSetting = _administratorSettingRepository.Find(x => x.CompanyID == model.CompanyID).FirstOrDefault(); if (administratorSetting != null) { Mapper.CreateMap <AdministratorSettingModel, tblAdministratorSetting>() .ForMember(dest => dest.AdministratorSettingID, opt => opt.Ignore()); tblAdministratorSetting adminsetting = (tblAdministratorSetting)Mapper.Map(model, administratorSetting); return(_administratorSettingRepository.SaveChanges()); } return(0); }
public int SaveAdminSetting(AdministratorSettingModel model) { if (model.AssignedEmployeeID.HasValue) { if (CheckDuplicate(model.AssignedEmployeeID.Value)) { throw new Exception("Already employee assigned as administrator"); } } model.CreatedDate = DateTime.Now; var administratorSetting = Mapper.DynamicMap <tblAdministratorSetting>(model); _administratorSettingRepository.Add(administratorSetting); _administratorSettingRepository.SaveChanges(); // Update role id in employee detail table var employeeDetail = _employeeDetailsRepository.Get(model.AssignedEmployeeID.Value); employeeDetail.EmpRoleID = 1; employeeDetail.LastUpdatedDate = DateTime.Now; employeeDetail.LastUpdatedBy = model.LastUpdatedBy; return(_employeeDetailsRepository.SaveChanges()); }
// PUT api/<controller>/5 public void Put([FromBody] AdministratorSettingModel model) { model.CompanyID = CompanyId; _administratorSettingService.UpdateAdminSetting(model); }
// POST api/<controller> public void Post([FromBody] AdministratorSettingModel model) { model.CompanyID = CompanyId; model.LastUpdatedBy = HttpContext.Current.User.Identity.GetUserName(); _administratorSettingService.SaveAdminSetting(model); }