Exemple #1
0
        public ActionResult MapBranch(ComponentBranchMappingViewModel vm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (_componentService.GetComponentList(filter: x => x.IsActive).Count == 0)
                    {
                        SystemMessages.Add(CommonStrings.No_Record, true, true);
                        return(RedirectToAction("MapBranch"));
                    }

                    BranchEditViewModel branchVM = _branchService.GetBranchById(vm.BranchId);
                    if (branchVM == null || !branchVM.IsActive || branchVM.IsHeadOffice)
                    {
                        SystemMessages.Add(ComponentStrings.Component_Map_Branch_Validation_InvalidBranch, true, true);
                        return(RedirectToAction("MapBranch"));;
                    }

                    foreach (var i in vm.MappedComponentList)
                    {
                        if (!_componentService.GetComponentById(i.ComponentId).IsActive)
                        {
                            SystemMessages.Add(String.Format(ComponentStrings.Component_Map_Branch_Validation_InvalidComponent, i.ComponentName), true, true);
                            return(RedirectToAction("MapBranch"));
                        }
                    }


                    if (!_branchService.MapComponent(vm))
                    {
                        SystemMessages.Add(CommonStrings.Server_Error, true, true);
                        return(RedirectToAction("MapBranch"));
                    }
                    else
                    {
                        SystemMessages.Add(ComponentStrings.Component_Branch_Map_Successfull_Msg, false, true);
                        return(RedirectToAction("MapBranch"));
                    }
                }
                catch (Exception ex)
                {
                    SystemMessages.Add(CommonStrings.Server_Error, true, true);
                    return(RedirectToAction("MapBranch"));
                }
            }

            ViewBag.Title          = ComponentStrings.Component_Map_Branch_Setup_Title;
            ViewBag.BranchDropDown = new SelectList(_branchService.GetBranchDropDown(x => x.IsActive && !x.IsHeadOffice), "Value", "Text");

            return(View("MapBranch"));
        }
Exemple #2
0
        public bool MapComponent(ComponentBranchMappingViewModel vm)
        {
            Branch branch = GetBranch(vm.BranchId);

            if (branch != null && !branch.IsHeadOffice)
            {
                foreach (var i in vm.MappedComponentList)
                {
                    Component component = _uow.ComponentRepository.Get(x => x.Id == i.ComponentId && x.IsActive).SingleOrDefault();
                    if (component != null)
                    {
                        if (i.Checked)
                        {
                            branch.Components.Add(component);
                        }

                        if (!i.Checked)
                        {
                            branch.Components.Remove(component);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            _uow.Save();

            return(true);
        }