Esempio n. 1
0
 public IActionResult Update(ArtistUpdate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     _artistService.Update(model, User.Claims);
     return(Ok());
 }
Esempio n. 2
0
        public bool UpdateArtist(ArtistUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Artists.Single(e => e.ArtistId == model.ArtistId);

                entity.ArtistName = model.ArtistName;
                entity.Birthdate  = model.Birthdate;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 3
0
        public ActionResult Update(int id)
        {
            var _service = CreateArtistService();
            var detail   = _service.GetArtistById(id);
            var model    =
                new ArtistUpdate
            {
                ArtistId   = detail.ArtistId,
                ArtistName = detail.ArtistName,
                Birthdate  = detail.Birthdate,
            };

            return(View(model));
        }
Esempio n. 4
0
        public void Update(ArtistUpdate model, IEnumerable <Claim> claims)
        {
            var entity = _dbContext.Artists.SingleOrDefault(m => m.Id == model.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Artist), model.Id);
            }

            if (!_authorizationService.AllowModifyEntity(claims, entity.UserId))
            {
                throw new NotAuthorizedException();
            }

            entity.Birthday  = model.Birthday;
            entity.Country   = model.Country;
            entity.FirstName = model.FirstName;
            entity.LastName  = model.LastName;
            _dbContext.Artists.Update(entity);
            _dbContext.SaveChanges();
        }
Esempio n. 5
0
        public ActionResult Update(int id, ArtistUpdate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ArtistId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var _service = CreateArtistService();

            if (_service.UpdateArtist(model))
            {
                TempData["SaveResult"] = "Your Artist was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your Artist could not be updated.");
            return(View(model));
        }