public ActionResult DepartmentInOrg(DepartmentInOrgViewModel deptInOrgViewModel, string buttonType)
        {
            if (buttonType == "Add")
                return RedirectToAction("AddDepartment", "Dashboard");
            ValidateDepartInOrgViewModel(deptInOrgViewModel);
            if (ModelState.IsValid)
            {
                deptInOrgViewModel.DepartmentInOrganizationViewModel = new List<DepartmentInOrganizationViewModel>();
                foreach (var department in deptInOrgViewModel.Departments)
                {
                    var deptInOrganization = new DepartmentInOrganizationViewModel();
                    deptInOrganization.DepartmentId = department.As<long>();
                    deptInOrganization.OrganizationId = SessionContext.CurrentUser.OrganizationId.Value;
                    deptInOrganization.Active = true;
                    deptInOrgViewModel.DepartmentInOrganizationViewModel.Add(deptInOrganization);
                }
                if (deptInOrgViewModel.DepartmentInOrganizationViewModel.IsCollectionValid())
                {
                    var mappedModel = Mapper.Map<List<DepartmentInOrganizationViewModel>, List<DepartmentInOrganization>>(deptInOrgViewModel.DepartmentInOrganizationViewModel);
                    //var checkDeptExists
                    _wcfService.InvokeService<IOrganizationService>((svc) => svc.AddDepartmentInOrg(mappedModel));
                    deptInOrgViewModel.CreationSuccessful = true;
                    deptInOrgViewModel.Message = "Thank you for choosing the Departments.";
                }

            }
            return View(deptInOrgViewModel);
        }
 private void ValidateDepartInOrgViewModel(DepartmentInOrgViewModel deptInOrgViewModel)
 {
     if (!deptInOrgViewModel.Departments.IsCollectionValid())
         ModelState.AddModelError("", " Please select the Departments you would like to include for your Organization.");
 }
 public ActionResult DepartmentInOrg()
 {
     var deptInOrgViewModel = new DepartmentInOrgViewModel()
     {
         Department = new List<Department>(),
         DepartmentInOrganizationViewModel = new List<DepartmentInOrganizationViewModel>()
     };
     var departments = _wcfService.InvokeService<IUserService, List<Department>>((svc) => svc.GetAllDepartment());
     var deptInOrg = _wcfService.InvokeService<IOrganizationService, List<DepartmentInOrganization>>((svc) => svc.GetDepartmentInOrganization(SessionContext.CurrentUser.OrganizationId.Value));
     var mappedDeptInOrg = Mapper.Map<List<DepartmentInOrganization>, List<DepartmentInOrganizationViewModel>>(deptInOrg);
     if (departments.IsCollectionValid())
         deptInOrgViewModel.Department = departments;
     if (deptInOrg.IsCollectionValid())
         deptInOrgViewModel.DepartmentInOrganizationViewModel = mappedDeptInOrg;
     return View(deptInOrgViewModel);
 }