public void AddCategory(AddCategoryBm bind) { Category model = Mapper.Instance.Map <AddCategoryBm, Category>(bind); this.Context.Categories.Add(model); this.Context.SaveChanges(); }
public void AddNewCategory(AddCategoryBm bm) { var entity = Mapper.Map <AddCategoryBm, Category>(bm); this.categories.Add(entity); this.categories.SaveChanges(); }
public ActionResult Add(AddCategoryBm bm) { if (ModelState.IsValid) { this.service.AddNewCategory(bm); return(this.RedirectToAction("All", "AdminPosts")); } return(this.View()); }
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)); }
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()); } }