public IActionResult Departments(int companyId) { ViewBag.Class = "inner-page"; AddDepartmentVM addDepartmentVM = new AddDepartmentVM(); addDepartmentVM.CompanyId = companyId; ViewBag.CompanyId = companyId; return(View(addDepartmentVM)); }
public IActionResult Create(int?id) { try { var dep = new AddDepartmentVM() { DepId = id }; return(View(dep)); } catch (Exception) { ViewBag.Error = "Something wrong"; return(View("Error")); } }
public IActionResult CreateDepartment(AddDepartmentVM addDepartmentVM) { if (!ModelState.IsValid) { ShowToaster("Please fill required fields", ToasterLevel.Danger); return(RedirectToAction("Departments", "Company", new { companyId = addDepartmentVM.CompanyId })); } var config = new MapperConfiguration(cfg => cfg.CreateMap <AddDepartmentVM, AddDepartmentDTO>()); var mapper = new Mapper(config); AddDepartmentDTO dto = mapper.DefaultContext.Mapper.Map <AddDepartmentDTO>(addDepartmentVM); _userService.CreateAndUpdateDepartment(dto); ShowToaster("Department created successfully", ToasterLevel.Success); return(RedirectToAction("Departments", "Company", new { companyId = dto.CompanyId })); }
public async Task <IActionResult> Create(AddDepartmentVM addDepartment) { try { if (ModelState.IsValid) { Department department = new Department() { Name = addDepartment.Name, ParentId = addDepartment.DepId }; await _departmentService.CreateDepartmentAsync(department); return(RedirectToAction("Index")); } return(View(addDepartment)); } catch (Exception) { ViewBag.Error = "Something wrong"; return(View("Error")); } }