public ActionResult ModuleInDepartment(ModuleInDepartmentViewModel moduleInDeptViewModel, string buttonType)
        {
            if (buttonType == "Add")
                return RedirectToAction("AddModule", "Dashboard");
            ValidateModuleInDepartmentVM(moduleInDeptViewModel);
            if (ModelState.IsValid)
            {
                var modInDeptLst = new List<ModuleInDepartment>();

                foreach (var mod in moduleInDeptViewModel.Modules)
                {
                    var modInDept = new ModuleInDepartment()
                    {
                        DepartmentId = moduleInDeptViewModel.DepartmentId,
                        ModuleId = mod.As<long>(),
                        Active = true
                    };
                    modInDeptLst.Add(modInDept);
                }
                _wcfService.InvokeService<IOrganizationService>((svc) => svc.AddModuleInDepartment(modInDeptLst));
                moduleInDeptViewModel.Message = "Thank you for choosing the modules.";
                moduleInDeptViewModel.CreationSuccessful = true;
            }
            return View(moduleInDeptViewModel);
        }
 public ActionResult AddModule(ModuleViewModel moduleViewModel)
 {
     ValidateModuleViewModel(moduleViewModel);
     if (ModelState.IsValid)
     {
         moduleViewModel.ModuleInDepartments = new List<ModuleInDepartment>();
         moduleViewModel.ModuleViewModels = new List<ModuleViewModel>();
         var deptInOrg = new ModuleInDepartment()
         {
             DepartmentId = moduleViewModel.DepartmentInOrgId,
             Active = true
         };
         moduleViewModel.ModuleInDepartments.Add(deptInOrg);
         moduleViewModel.IsActive = true;
         var mappedModule = Mapper.Map<ModuleViewModel, Module>(moduleViewModel);
         _wcfService.InvokeService<IOrganizationService>((svc) => svc.AddModule(mappedModule));
         moduleViewModel.CreationSuccessful = true;
         moduleViewModel.Message = "The Module '{0}' is saved successfully.".ToFormat(moduleViewModel.ModuleName);
         var moduleInDept = _wcfService.InvokeService<IOrganizationService, List<ModuleInDepartment>>((svc) => svc.GetModuleInDepartment(moduleViewModel.DepartmentInOrgId));
         foreach (var mod in moduleInDept)
         {
             var module = _wcfService.InvokeService<IOrganizationService, Module>((svc) => svc.GetModuleById(mod.ModuleId.Value));
             var mappedModuleViewModel = Mapper.Map<Module, ModuleViewModel>(module);
             moduleViewModel.ModuleViewModels.Add(mappedModuleViewModel);
         }
     }
     return View(moduleViewModel);
 }