Exemple #1
0
        public void AddCategory(AddCategoryBm bind)
        {
            Category model = Mapper.Instance.Map <AddCategoryBm, Category>(bind);

            this.Context.Categories.Add(model);
            this.Context.SaveChanges();
        }
Exemple #2
0
        public void AddNewCategory(AddCategoryBm bm)
        {
            var entity = Mapper.Map <AddCategoryBm, Category>(bm);

            this.categories.Add(entity);
            this.categories.SaveChanges();
        }
Exemple #3
0
        public ActionResult Add(AddCategoryBm bm)
        {
            if (ModelState.IsValid)
            {
                this.service.AddNewCategory(bm);
                return(this.RedirectToAction("All", "AdminPosts"));
            }

            return(this.View());
        }
Exemple #4
0
        public void AddCategory(AddCategoryBm bm)
        {
            Category category = new Category
            {
                Title = bm.Title
            };

            this.Context.Categories.Add(category);
            this.Context.SaveChanges();
        }
        public IHttpActionResult Post(AddCategoryBm bind)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            if (this._service.CategoryNameExists(bind.Name))
            {
                return(this.BadRequest());
            }

            this._service.AddCategory(bind);
            return(this.StatusCode(HttpStatusCode.Created));
        }
Exemple #6
0
 public ActionResult Add(AddCategoryBm bm)
 {
     if (!this.ModelState.IsValid)
     {
         return(View(bm));
     }
     try
     {
         this.service.AddCategory(bm);
         return(RedirectToAction("all"));
     }
     catch (DbEntityValidationException ex)
     {
         var error = ex.EntityValidationErrors.First().ValidationErrors.First();
         this.ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
         return(this.View());
     }
 }