Exemple #1
0
        public ActionResult Edit(int id, AlbumEdit model)
        {
            if (!ModelState.IsValid)
            {
                //ViewBag
                ViewBag.Artists = new SelectList(_db.Artists.ToList(), "ArtistID", "ArtistName");
                return(View(model));
            }

            if (model.AlbumID != id)
            {
                //ViewBag
                ViewBag.Artists = new SelectList(_db.Artists.ToList(), "ArtistID", "ArtistName");
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateAlbumService();

            if (service.UpdateAlbum(model))
            {
                TempData["SaveResult"] = $" {model.AlbumTitle} was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", $" {model.AlbumTitle} could not be updated.");
            return(View(model));
        }
Exemple #2
0
        public ActionResult Edit(AlbumEdit model)
        {
            if (!OptionalDateTime.IsValid(model.ReleaseYear, model.ReleaseDay, model.ReleaseMonth))
            {
                ModelState.AddModelError("ReleaseYear", "Invalid date");
            }

            var coverPicUpload = Request.Files["coverPicUpload"];
            PictureDataContract pictureData = ParseMainPicture(coverPicUpload, "CoverPicture");

            ParseAdditionalPictures(coverPicUpload, model.Pictures);

            if (!ModelState.IsValid)
            {
                var oldContract = Service.GetAlbumForEdit(model.Id);
                model.CopyNonEditableFields(oldContract);
                return(View(model));
            }

            var contract = model.ToContract();

            Service.UpdateBasicProperties(contract, pictureData);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
 //EDIT
 public bool EditAlbum(AlbumEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity = ctx
                      .Albums
                      .Single(a => a.AlbumId == model.AlbumId);
         entity.Title = model.Title;
         return(ctx.SaveChanges() == 1);
     }
 }
        //EditAlbum
        public bool EditAlbum(AlbumEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Albums
                             .Single(album => album.AlbumID == model.AlbumID);

                entity.AlbumName = model.AlbumName;
                entity.AlbumArt  = model.AlbumArt;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #5
0
        //GET Album/Edit
        public ActionResult Edit(int id)
        {
            var service = new AlbumService();
            var detail  = service.GetAlbumByID(id);
            var model   =
                new AlbumEdit
            {
                AlbumID   = detail.AlbumID,
                AlbumName = detail.AlbumName,
                AlbumArt  = detail.AlbumArt
            };

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            var service = CreateAlbumService();
            var detail  = service.GetByAlbumId(id);
            var model   =
                new AlbumEdit
            {
                AlbumId          = detail.AlbumId,
                Title            = detail.Title,
                AlbumDescription = detail.AlbumDescription
            };

            return(View(model));
        }
Exemple #7
0
        public bool UpdateAlbum(AlbumEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Albums
                    .Single(e => e.AlbumId == model.AlbumId /* && e.OwnerId == _userId*/);
                //entity.AlbumId = model.AlbumId;
                entity.Title = model.Title;


                return(ctx.SaveChanges() == 1);
            }
        }
        /// <summary>
        /// Edit an album by ID
        /// </summary>
        /// <param name="album">Pass an ID</param>
        /// <returns></returns>
        public IHttpActionResult Put(AlbumEdit album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateAlbumService();

            if (!service.UpdateAlbum(album))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool UpdateAlbum(AlbumEdit model)
        {
            using (var db = new ApplicationDbContext())
            {
                var entity =
                    db
                    .Albums
                    .Single(e => e.AlbumID == model.AlbumID);

                entity.ArtistID    = model.ArtistID;
                entity.AlbumTitle  = model.AlbumTitle;
                entity.ReleaseDate = model.ReleaseDate;

                return(db.SaveChanges() == 1);
            }
        }
Exemple #10
0
        public ActionResult Edit(int id)
        {
            //ViewBag
            ViewBag.Artists = new SelectList(_db.Artists.ToList(), "ArtistID", "ArtistName");
            var service = CreateAlbumService();
            var detail  = service.GetAlbumById(id);
            var model   =
                new AlbumEdit
            {
                AlbumID     = detail.AlbumID,
                ArtistID    = detail.ArtistID,
                AlbumTitle  = detail.AlbumTitle,
                ReleaseDate = detail.ReleaseDate
            };

            return(View(model));
        }
Exemple #11
0
        public bool UpdateAlbum(AlbumEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Albums
                    .Single(e => e.AlbumId == model.AlbumId && e.OwnerId == _userId);


                entity.AlbumName        = model.AlbumName;
                entity.Rating           = model.Rating;
                entity.CulumativeRating = model.CulumativeRating;
                entity.NumberOfRatings  = model.NumberOfRatings;
                entity.ArtistId         = model.ArtistId;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #12
0
        public ActionResult Edit(int id, AlbumEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = new AlbumService();

            if (service.EditAlbum(model))
            {
                TempData["SaveResult"] = "Album was updated";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Album could not be updated");
            return(View());
        }
        public ActionResult Edit(int id, AlbumEdit newItem)
        {
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to do the update
                var editedItem = m.EditAlbum(newItem);

                if (editedItem == null)
                {
                    // There was a problem updating the object
                    var editForm = AutoMapper.Mapper.Map<AlbumEditForm>(newItem);
                    editForm.Genres = new SelectList(m.AllGenres(), newItem.Genre);

                    ModelState.AddModelError("modelState", "There was an error. (The edited data could not be saved.)");
                    return View(editForm);
                }
                else
                {
                    // Redirect
                    // Could do other things here
                    return RedirectToAction("details", new { id = editedItem.Id });
                }
            }
            else
            {
                // There was a problem with model validation or identifiers that don't match
                var editForm = AutoMapper.Mapper.Map<AlbumEditForm>(newItem);
                editForm.Genres = new SelectList(m.AllGenres(), newItem.Genre);

                ModelState.AddModelError("modelState", "There was an error. (The incoming data is invalid.)");

                return View(editForm);
            }
        }
Exemple #14
0
        // Edit album
        public AlbumBase EditAlbum(AlbumEdit newItem)
        {
            // Validate the incoming data
            var fetchedObject = ds.Albums
                .Include("Artist")
                .SingleOrDefault(a => a.Id == newItem.Id);

            if (fetchedObject == null)
            {
                return null;
            }
            else
            {
                // Update the object with the incoming values
                // Before doing this, we may have to do some business-rule validations
                ds.Entry(fetchedObject).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                // Prepare and return the object
                return Mapper.Map<AlbumBase>(fetchedObject);
            }
        }