Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 public void PutTattoo([FromBody] TattooDTO value)
 {
     tattooService.Add(value);
     tattooService.Save();
 }
Exemplo n.º 3
0
 public void PostTattoo([FromBody] TattooDTO value)
 {
     tattooService.Update(value);
 }