Example #1
0
 private void ValidateFunctionalOrganizationModel(FunctionalOrganization functionalOrganization)
 {
     if (_functionalOrganizationService.IsNameDuplicated(functionalOrganization.Type_Id, functionalOrganization.Name))
     {
         ModelState.AddModelError(ViewRes.Controllers.Shared.Name, ViewRes.Controllers.Shared.NameText);
     }
 }
 public FunctionalOrganizationViewModel(FunctionalOrganization functionalOrganization, SelectList typesList,
                                        SelectList typesParentList, SelectList fosParentList)
 {
     this.functionalOrganization = functionalOrganization;
     this.typesList       = typesList;
     this.typesParentList = typesParentList;
     this.fosParentList   = fosParentList;
 }
Example #3
0
 public ActionResult Create(FunctionalOrganization functionalOrganization)
 {
     ValidateFunctionalOrganizationModel(functionalOrganization);
     if (ModelState.IsValid)
     {
         if (_functionalOrganizationService.Add(functionalOrganization))
         {
             return(RedirectToAction("Index", new { @type_id = functionalOrganization.Type_Id }));
         }
     }
     InitializeViews(null, null);
     return(View(_functionalOrganizationViewModel));
 }
        private void CreateEntities(int type)
        {
            FunctionalOrganizationsServices fos = new FunctionalOrganizationsServices();


            foreach (FunctionalOrganization functorg in fos.GetByCompany(1117))
            {
                FunctionalOrganization newFunctOrg = new FunctionalOrganization();
                newFunctOrg.Name      = functorg.Name;
                newFunctOrg.ShortName = functorg.ShortName;
                newFunctOrg.Type_Id   = type;
                if (!fos.Add(newFunctOrg))
                {
                    this.Ok = false;
                }
            }
        }
Example #5
0
        private void InitializeViews(int?functionalOrganization_id, int?functionalOrganizationType_id)
        {
            FunctionalOrganization functionalOrganization;
            SelectList             typesList;
            SelectList             typesParentList;
            SelectList             fosParentList;
            User user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (functionalOrganization_id != null)
            {
                functionalOrganization = _functionalOrganizationService.GetById((int)functionalOrganization_id);
                if (functionalOrganization.FOParent_Id.HasValue)
                {
                    typesParentList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganization.Parent.Type_Id);
                    typesList       = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesChildrenByTypeForDropDownList(functionalOrganization.Parent.Type_Id), "Key", "Value", functionalOrganization.Type_Id);
                    fosParentList   = new SelectList(_functionalOrganizationService.GetFunctionalOrganizationsByTypeForDropDownList(functionalOrganization.Parent.Type_Id), "Key", "Value", functionalOrganization.FOParent_Id);
                }
                else
                {
                    typesList       = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganization.Type_Id);
                    typesParentList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                    fosParentList   = new SelectList(new Dictionary <int, string>(), "Key", "Value");
                }
            }
            else
            {
                functionalOrganization = new FunctionalOrganization();
                typesParentList        = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                fosParentList          = new SelectList(new Dictionary <int, string>(), "Key", "Value");
                if (functionalOrganizationType_id != null)
                {
                    typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganizationType_id.Value);
                    functionalOrganization.Type_Id = functionalOrganizationType_id.Value;
                }
                else
                {
                    typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                }
            }
            _functionalOrganizationViewModel = new FunctionalOrganizationViewModel(functionalOrganization, typesList, typesParentList, fosParentList);
        }
Example #6
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     if (GetAuthorization(_functionalOrganizationService.GetById(id).FunctionalOrganizationType.Company_Id))
     {
         try
         {
             FunctionalOrganization functionalOrganization = _functionalOrganizationService.GetById(id);
             UpdateModel(functionalOrganization, "functionalOrganization");
             _functionalOrganizationService.SaveChanges();
             return(RedirectToAction("Index", new { @type_id = functionalOrganization.Type_Id }));
         }
         catch
         {
             InitializeViews(id, null);
             return(View(_functionalOrganizationViewModel));
         }
     }
     else
     {
         return(RedirectToLogOn());
     }
 }