public void AddNewCategory(NewCategoryBindingModel bind) { Category category = Mapper.Map <NewCategoryBindingModel, Category>(bind); this.Context.Categories.Add(category); this.Context.SaveChanges(); }
public bool IsNewCategoryValid(NewCategoryBindingModel model) { if (!string.IsNullOrEmpty(model.Name)) { return(false); } return(true); }
//public Category GetCategoryFromBind(NewCategoryBindingModel model) //{ // return this.Context.Categories.First(c => c.Name == model.Name); //} public void AddNewCategory(NewCategoryBindingModel model) { this.Context.Categories.Add(new Category() { Name = model.Name }); this.Context.SaveChanges(); }
public void AddNewCategory(NewCategoryBindingModel ncbm) { Category category = new Category() { Name = ncbm.Name }; this.Context.Categories.Add(category); this.Context.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Name")] NewCategoryBindingModel category) { if (ModelState.IsValid) { this._service.Add(category); return(RedirectToAction("Index")); } return(View(category)); }
public void AddNewCategoryFromBind(NewCategoryBindingModel model) { var category = new Category() { Name = model.Name }; this.Context.Categories.Add(category); this.Context.SaveChanges(); }
public void New(HttpResponse response, HttpSession session, NewCategoryBindingModel bind) { this.GetAuthenticatedUser(response, session); if (!this.service.IsNewCategoryValid(bind)) { this.Redirect(response, "/categories/new"); } this.service.AddNewCategory(bind); this.Redirect(response, "/categories/all"); }
public bool IsNewCategoryBindingModelValid(NewCategoryBindingModel ncbm) { // Name lenght check if (ncbm.Name.Length > 30) { return(false); } // Same name check if (this.Context.Categories.Any(n => n.Name == ncbm.Name)) { return(false); } return(true); }
public IActionResult New(NewCategoryBindingModel catModel, HttpResponse response, HttpSession session) { if (!AuthenticationManager.IsAuthenticated(session)) { this.Redirect(response, "/forum/login"); return(null); } var user = AuthenticationManager.GetAuthenticatedUser(session.Id); if (user.IsAdmin == false) { this.Redirect(response, "/home/topics"); return(null); } this.service.AddNewCategoryFromBind(catModel); this.Redirect(response, "/categories/all"); return(null); }
public void New(HttpResponse response, HttpSession session, NewCategoryBindingModel model) { if (!AuthenticatedManager.IsAuthenticated(session.Id)) { this.Redirect(response, "/forum/login"); } User activeUser = AuthenticatedManager.GetAuthenticatedUser(session.Id); if (!activeUser.IsAdmin) { this.Redirect(response, "/home/topics"); } if (!this.service.IsNewCategoryValid(model)) { this.Redirect(response, "/categories/new"); } //Category category = this.service.GetCategoryFromBind(model); this.service.AddNewCategory(model); this.Redirect(response, "/categories/all"); }
public void Add(NewCategoryBindingModel category) { this.Context.Categories.Add(Mapper.Map <NewCategoryBindingModel, Category>(category)); this.Context.SaveChanges(); }
public IActionResult <NavbarViewModel> New(HttpResponse response, HttpSession session, NewCategoryBindingModel ncbm) { if (this.signInManagerService.IsAuthenticated(session)) { if (this.signInManagerService.GetAuthenticatedUser(session).Role == Enums.UserRole.Administrator) { if (this.categoriesService.IsNewCategoryBindingModelValid(ncbm)) { this.categoriesService.AddNewCategory(ncbm); this.Redirect(response, "/categories/all"); return(null); } this.Redirect(response, "/categories/new"); return(null); } } this.Redirect(response, "/home/topics"); return(null); }