private void ValidateTypeModel(FunctionalOrganizationType type) { if (_typeService.IsNameDuplicated(type.Company_Id, type.Name)) { ModelState.AddModelError(ViewRes.Controllers.Shared.Name, ViewRes.Controllers.Shared.NameText); } }
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)); }
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); }
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); }
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()); } }
private bool GetAuthorization(FunctionalOrganizationType type) { return(new SharedAdminAuthorization(new UsersServices().GetByUserName(User.Identity.Name), new CompaniesServices().GetById(type.Company_Id)).isAuthorizated()); }
public FunctionalOrganizationTypeViewModel(FunctionalOrganizationType type, SelectList typesList) { this.type = type; this.typesList = typesList; }