Пример #1
0
        public void AddNewCategory(NewCategoryBindingModel bind)
        {
            Category category = Mapper.Map <NewCategoryBindingModel, Category>(bind);

            this.Context.Categories.Add(category);
            this.Context.SaveChanges();
        }
Пример #2
0
 public bool IsNewCategoryValid(NewCategoryBindingModel model)
 {
     if (!string.IsNullOrEmpty(model.Name))
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
        //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();
        }
Пример #4
0
        public void AddNewCategory(NewCategoryBindingModel ncbm)
        {
            Category category = new Category()
            {
                Name = ncbm.Name
            };

            this.Context.Categories.Add(category);
            this.Context.SaveChanges();
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] NewCategoryBindingModel category)
        {
            if (ModelState.IsValid)
            {
                this._service.Add(category);
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Пример #6
0
        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");
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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");
        }
Пример #11
0
 public void Add(NewCategoryBindingModel category)
 {
     this.Context.Categories.Add(Mapper.Map <NewCategoryBindingModel, Category>(category));
     this.Context.SaveChanges();
 }
Пример #12
0
        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);
        }