コード例 #1
0
 private void ValidateTypeModel(FunctionalOrganizationType type)
 {
     if (_typeService.IsNameDuplicated(type.Company_Id, type.Name))
     {
         ModelState.AddModelError(ViewRes.Controllers.Shared.Name, ViewRes.Controllers.Shared.NameText);
     }
 }
コード例 #2
0
 public ActionResult Create(FunctionalOrganizationType type)
 {
     type.Company_Id = (int)new UsersServices().GetByUserName(User.Identity.Name.ToString()).Company_Id;
     ValidateTypeModel(type);
     if (ModelState.IsValid)
     {
         if (_typeService.Add(type))
         {
             return(RedirectToAction("Index"));
         }
     }
     InitializeViews(null);
     return(View(_typeViewModel));
 }
コード例 #3
0
        private int CreateType()
        {
            FunctionalOrganizationType type = new FunctionalOrganizationType();

            type.Company_Id = Company.Id;
            type.Name       = "Áreas";
            type.ShortName  = "Área";
            if (!new FunctionalOrganizationTypesServices().Add(type))
            {
                this.Ok = false;
                return(0);
            }
            return(type.Id);
        }
コード例 #4
0
        private void InitializeViews(int?type_id)
        {
            FunctionalOrganizationType type;
            SelectList typesList;
            User       user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (type_id != null)
            {
                type      = _typeService.GetById((int)type_id);
                typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", type.FOTParent_Id);
            }
            else
            {
                type      = new FunctionalOrganizationType();
                typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
            }
            _typeViewModel = new FunctionalOrganizationTypeViewModel(type, typesList);
        }
コード例 #5
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     if (GetAuthorization(_typeService.GetById(id)))
     {
         try
         {
             FunctionalOrganizationType type = _typeService.GetById(id);
             UpdateModel(type, "type");
             _typeService.SaveChanges();
             return(RedirectToAction("Index"));
         }
         catch
         {
             InitializeViews(id);
             return(View(_typeViewModel));
         }
     }
     else
     {
         return(RedirectToLogOn());
     }
 }
コード例 #6
0
 private bool GetAuthorization(FunctionalOrganizationType type)
 {
     return(new SharedAdminAuthorization(new UsersServices().GetByUserName(User.Identity.Name),
                                         new CompaniesServices().GetById(type.Company_Id)).isAuthorizated());
 }
コード例 #7
0
 public FunctionalOrganizationTypeViewModel(FunctionalOrganizationType type, SelectList typesList)
 {
     this.type      = type;
     this.typesList = typesList;
 }