public ActionResult AddDepartment(DepartmentViewModel departmentViewModel, string buttonType)
        {
            if (buttonType == "Next")
                return RedirectToAction("AddModule", "Dashboard");
            ValidateDepartmentViewModel(departmentViewModel);
            if (ModelState.IsValid)
            {
                departmentViewModel.DepartmentInOrganizationViewModels = new List<DepartmentInOrganizationViewModel>();
                var departmentInOrg = new DepartmentInOrganizationViewModel() { OrganizationId = SessionContext.CurrentUser.OrganizationId.Value, Active = true };
                departmentViewModel.DepartmentInOrganizationViewModels.Add(departmentInOrg);
                departmentViewModel.IsActive = true;
                departmentViewModel.CreatedBy = departmentViewModel.UpdatedBy = SessionContext.CurrentUser.Id;
                departmentViewModel.CreatedDate = departmentViewModel.UpdatedDate = DateTime.Now;
                departmentViewModel.DepartmentViewModels = new List<DepartmentViewModel>();

                var mappedDepartModel = Mapper.Map<DepartmentViewModel, Department>(departmentViewModel);
                _wcfService.InvokeService<IOrganizationService>((svc) => svc.AddDepartment(mappedDepartModel));

                var departmentsInOrg = _wcfService.InvokeService<IOrganizationService, List<Department>>((svc) => svc.GetDepartmentInOrg(SessionContext.CurrentUser.OrganizationId.Value));
                var mappedDeptInOrg = Mapper.Map<List<Department>, List<DepartmentViewModel>>(departmentsInOrg);

                if (mappedDeptInOrg.IsCollectionValid())
                    departmentViewModel.DepartmentViewModels = mappedDeptInOrg;

                departmentViewModel.CreationSuccessful = true;
                departmentViewModel.Message = "The Department '{0}' is saved successfully.".ToFormat(departmentViewModel.DepartmentName);
            }
            return View(departmentViewModel);
        }
 private void ValidateDepartmentViewModel(DepartmentViewModel departmentViewModel)
 {
     if (departmentViewModel.DepartmentName.Trim().IsEmpty() || departmentViewModel.DepartmentName.IsNull())
         ModelState.AddModelError("DepartmentName", "Department Name is mandatory.");
     if (departmentViewModel.DepartmentDescription.Trim().IsEmpty() || departmentViewModel.DepartmentDescription.IsNull())
         ModelState.AddModelError("DepartmentDescription", "Department Description is mandatory.");
 }
 public ActionResult AddDepartment()
 {
     var departmentViewModel = new DepartmentViewModel() { DepartmentViewModels = new List<DepartmentViewModel>() };
     var departmentInOrg = _wcfService.InvokeService<IOrganizationService, List<Department>>((svc) => svc.GetDepartmentInOrg(SessionContext.CurrentUser.OrganizationId.Value));
     var mappedDepartmentVM = Mapper.Map<List<Department>, List<DepartmentViewModel>>(departmentInOrg);
     if (departmentInOrg.IsCollectionValid())
         departmentViewModel.DepartmentViewModels = mappedDepartmentVM;
     return View(departmentViewModel);
 }