Beispiel #1
0
        public IActionResult Departments(int companyId)
        {
            ViewBag.Class = "inner-page";
            AddDepartmentVM addDepartmentVM = new AddDepartmentVM();

            addDepartmentVM.CompanyId = companyId;
            ViewBag.CompanyId         = companyId;

            return(View(addDepartmentVM));
        }
Beispiel #2
0
 public IActionResult Create(int?id)
 {
     try
     {
         var dep = new AddDepartmentVM()
         {
             DepId = id
         };
         return(View(dep));
     }
     catch (Exception)
     {
         ViewBag.Error = "Something wrong";
         return(View("Error"));
     }
 }
Beispiel #3
0
        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 }));
        }
Beispiel #4
0
        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"));
            }
        }