public CategoryModel(Category category) { this.Id = category.Id; this.Url = category.Url; this.Name = category.Name; this.CreateDate = category.CreateDate; this.IsPublic = category.IsPublic; }
public ActionResult Create(CategoryModel model) { if (ModelState.IsValid) { model.Url = model.Url.ReplaceWhiteSpacesWithHyphens().ToLower(); if (!Context.Categories.Any(c => c.Url.ToLower() == model.Url.ToLower())) { Category newCategory = new Category { CreateDate = DateTime.Now }; model.UpdateCategory(newCategory); Context.Categories.Add(newCategory); Context.SaveChanges(); return RedirectToAction("AllCategories"); } ModelState.AddModelError("Name", Config.TextErrorMessage); } return View(model); }
/// <summary> /// Updates given Category instance according to model. /// Updating affects Url, Name and IsPublic properties of given instance. /// </summary> public void UpdateCategory(Category category) { category.Url = this.Url; category.Name = this.Name; category.IsPublic = this.IsPublic; }