public ActionResult Edit(int id, TattooViewModel _tattoo) { var tattoo = tattooService.Get(id); if (ModelState.IsValid) { try { tattoo.Name = _tattoo.Name; tattoo.Price = _tattoo.Price; tattoo.StyleName = _tattoo.StyleName; tattoo.StyleId = _tattoo.StyleId; tattoo.AuthorName = _tattoo.AuthorName; tattoo.AuthorId = _tattoo.AuthorId; tattoo.Image = _tattoo.Image != null?ImageConverter.GetBytes(_tattoo.Image) : tattoo.Image; tattooService.Update(tattoo); tattooService.Save(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(RedirectToAction(nameof(List))); } ViewData["StyleId"] = new SelectList(styleService.GetAll(), "Id", "Id", _tattoo.StyleId); ViewData["AuthorId"] = new SelectList(authorService.GetAll(), "Id", "Id", _tattoo.AuthorId); return(View(_tattoo)); }
public ActionResult Create(TattooViewModel _tattoo) { TattooDTO tattoo = new TattooDTO(); if (ModelState.IsValid) { if (tattooService.GetAll().Where(x => x.Name == _tattoo.Name).Count() > 0) { return(RedirectToAction("Error", new { exeption = "The tattoo already exist!" })); } else { tattoo.Name = _tattoo.Name; tattoo.Price = _tattoo.Price; tattoo.StyleName = _tattoo.StyleName; tattoo.StyleId = _tattoo.StyleId; tattoo.AuthorName = authorService.GetAll().FirstOrDefault(x => x.AuthorId == _tattoo.AuthorId).Name; tattoo.AuthorId = _tattoo.AuthorId; tattoo.Image = _tattoo.Image != null?ImageConverter.GetBytes(_tattoo.Image) : null; tattooService.Add(tattoo); tattooService.Save(); return(RedirectToAction(nameof(List))); } } ViewData["StyleId"] = new SelectList(styleService.GetAll(), "Id", "Name", _tattoo.StyleId); ViewData["AuthorId"] = new SelectList(authorService.GetAll(), "AuthorId", "Name", _tattoo.AuthorId); return(View(_tattoo)); }
public ActionResult Delete(int id) { var tattoo = tattooService.Get(id); if (tattoo == null) { return(NotFound()); } var _tattoo = new TattooViewModel { Name = tattoo.Name, Price = tattoo.Price, StyleName = styleService.GetAll().FirstOrDefault(x => x.Id == tattoo.StyleId).Name, StyleId = tattoo.StyleId, AuthorName = authorService.GetAll().FirstOrDefault(x => x.AuthorId == tattoo.AuthorId).Name, AuthorId = tattoo.AuthorId }; ViewBag.Image = tattoo.Image; return(View(_tattoo)); }
public ActionResult Details(int id) { var tattoo = tattooService.Get(id); if (tattoo == null) { return(NotFound()); } var _tattoo = new TattooViewModel { TattooId = tattoo.TattoId, Name = tattoo.Name, Price = tattoo.Price, StyleId = tattoo.StyleId, StyleName = styleService.GetAll().FirstOrDefault(x => x.Id == tattoo.StyleId).Name, AuthorId = tattoo.AuthorId, AuthorName = authorService.GetAll().FirstOrDefault(x => x.AuthorId == tattoo.AuthorId).Name }; ViewBag.Image = tattoo.Image; ViewBag.IsAdmin = HttpContext.User.IsInRole("Administrator"); return(View(_tattoo)); }
public ActionResult Edit(int id) { var tattoo = tattooService.Get(id); if (tattoo == null) { return(NotFound()); } var _tattoo = new TattooViewModel() { Name = tattoo.Name, Price = tattoo.Price, StyleName = tattoo.StyleName, StyleId = tattoo.StyleId, AuthorName = tattoo.AuthorName, AuthorId = tattoo.AuthorId }; ViewBag.Image = tattoo.Image; ViewData["Styles"] = new SelectList(styleService.GetAll(), "Id", "Name"); ViewData["Authors"] = new SelectList(authorService.GetAll(), "AuthorId", "Name"); return(View(_tattoo)); }