public ActionResult GroupEdit(GroupsOfEmployeeModel model) { if (ModelState.IsValid) { ViewBag.Departmanlar = _serviceDepartments.GetAll().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); _serviceGroupsOfEmployee.Update(model.ModelToEnity(true)); } return(RedirectToAction("GroupList")); }
public static GroupsOfEmployee ModelToEnity(this GroupsOfEmployeeModel model, bool virtualActive = false) { GroupsOfEmployee entity = new GroupsOfEmployee() { DepartmentId = model.DepartmentId, Name = model.Name, Id = model.Id, IsActive = model.IsActive }; if (virtualActive) { entity.Employees = model.Employees; entity.Department = model.Department; } return(entity); }
public static GroupsOfEmployeeModel EntityToModel(this GroupsOfEmployee entity, bool virtualActive = false) { try { GroupsOfEmployeeModel model = new GroupsOfEmployeeModel() { DepartmentId = entity.DepartmentId, Name = entity.Name, IsActive = entity.IsActive, Id = entity.Id }; if (virtualActive) { model.Department = entity.Department; model.Employees = entity.Employees; } return(model); } catch (Exception) { return(new GroupsOfEmployeeModel()); } }