예제 #1
0
        public ActionResult Edit(int?id, TrackEdit newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                // Our "version 1" approach is to display the "edit form" again
                return(RedirectToAction("Edit", new { id = newItem.Id }));
            }

            if (id.GetValueOrDefault() != newItem.Id)
            {
                // This appears to be data tampering, so redirect the user away
                return(RedirectToAction("Index"));
            }

            // Attempt to do the update
            var editedItem = m.TrackEdit(newItem);

            if (editedItem == null)
            {
                // There was a problem updating the object
                // Our "version 1" approach is to display the "edit form" again
                return(RedirectToAction("edit", new { id = newItem.Id }));
            }
            else
            {
                // Show the details view, which will have the updated data
                return(RedirectToAction("details", new { id = newItem.Id }));
            }
        }
예제 #2
0
        public ActionResult Edit(int?id, TrackEdit collection)
        {
            collection.Clerk = HttpContext.User.Identity.Name;
            ModelState.Clear();

            if (!TryValidateModel(collection))
            {
                return(RedirectToAction("Edit", new { id = collection.Id }));
            }

            if (id.GetValueOrDefault() != collection.Id)
            {
                return(RedirectToAction("Index"));
            }

            var editedItem = m.TrackEdit(collection);

            if (editedItem == null)
            {
                return(RedirectToAction("Edit", new { id = collection.Id }));
            }
            else
            {
                return(RedirectToAction("Details", new { id = collection.Id }));
            }
        }
예제 #3
0
        public TrackWithDetail TrackEdit(TrackEdit newItem)
        {
            var o = ds.Tracks.Find(newItem.Id);

            if (o == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(o).CurrentValues.SetValues(newItem);
                ds.SaveChanges();
                return(mapper.Map <TrackWithDetail>(o));
            }
        }
예제 #4
0
        public TrackWithDetail TrackEdit(TrackEdit newItem)
        {
            var o = ds.Tracks.Include("Albums").SingleOrDefault(v => v.Id == newItem.Id);

            if (o == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(o).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                return(Mapper.Map <TrackWithDetail>(o));
            }
        }