示例#1
0
        public IHttpActionResult PutArtist(int id, Artist artist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != artist.ArtistId)
            {
                return(BadRequest());
            }

            _db.Entry(artist).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public async Task <IActionResult> PutArtist([FromRoute] int id, [FromBody] Artist artist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != artist.ArtistId)
            {
                return(BadRequest());
            }

            _context.Entry(artist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IHttpActionResult PutGenre(int id, Genre genre)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != genre.GenreId)
            {
                return(BadRequest());
            }

            _db.Entry(genre).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GenreExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult Edit([Bind(Include = "ArtistID,Name")] Artist artist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(artist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(artist));
 }
 public ActionResult Edit([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,Address,City,State,PostalCode,Country,Phone,Email,Total")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(order));
 }
示例#6
0
 public ActionResult Edit([Bind(Include = "UserId,UserName,Password")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
示例#7
0
 public ActionResult Edit(Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(album));
 }
示例#8
0
 public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
示例#9
0
 public ActionResult Edit([Bind(Include = "StudentId,StuNo,Name,Gender,height,weight")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
示例#10
0
 public ActionResult Edit([Bind(Include = "AlbumId,GenreId,AritstId,Title,Price,AlbumArtUrl")] Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
     return(View(album));
 }
示例#11
0
 public ActionResult Edit([Bind(Include = "MusicId,Name,Description,Price,ArtistId,CategoryId")] Music music)
 {
     if (ModelState.IsValid)
     {
         db.Entry(music).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ArtistId   = new SelectList(db.Artists, "ArtistId", "Name", music.ArtistId);
     ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", music.CategoryId);
     return(View(music));
 }
 public ActionResult Edit(Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
     ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
     return(View(album));
 }
示例#13
0
        public ActionResult Buy(int id)
        {
            var userName = User.Identity.Name;

            if (userName == null || userName == "")
            {
                userName = "******";
            }

            var album = db.Albums.Find(id);
            var cart  = db.Carts.SingleOrDefault(c => c.UserName == userName);

            if (cart == null)
            {
                cart = new Cart {
                    UserName  = userName,
                    CartItems = new List <OrderDetail>()
                };
                db.Carts.Add(cart);
            }
            else
            {
                cart.CartItems = db.OrderDetails.Include(od => od.Album).Where(od => od.CartId == cart.CartId).ToList();
            }

            if (album != null)
            {
                var cartItem = cart.CartItems.Find(item => (item.AlbumId == album.AlbumId));

                if (cartItem == null)
                {
                    cartItem = new OrderDetail {
                        AlbumId  = album.AlbumId,
                        Album    = album,
                        Quantity = 1
                    };
                    cart.CartItems.Add(cartItem);
                    db.OrderDetails.Add(cartItem);
                }
                else
                {
                    cartItem.Quantity++;
                    db.Entry(cartItem).State = EntityState.Modified;
                }
            }
            db.SaveChanges();
            return(PartialView("Cart", cart.CartItems));
        }
示例#14
0
        public ActionResult Edit([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,Address,City,State,PostalCode,Country,Phone,Email,Total")] Order order)
        {
            try {
                if (ModelState.IsValid)
                {
                    db.Entry(order).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes.  Try again, and if the problem persists, see your system administrator.");
            }

            return(View(order));
        }
 public ActionResult Edit([Bind(Include = "ArtistId,Name")] Artist artist)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(artist).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Operation failed. Please contact your system administrator if the problem persists.");
     }
     return(View(artist));
 }
示例#16
0
 public ActionResult Edit([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,Address,City,State,PostalCode,Country,Phone,Email,Total")] Order order)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(order).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Operation failed. Please contact your system administrator if the problem persists.");
     }
     return(View(order));
 }
示例#17
0
 public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
 {
     try {
         if (ModelState.IsValid)
         {
             db.Entry(album).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         ModelState.AddModelError("", "Unable to save changes.  Try again, and if the problem persists, see your system administrator.");
     }
     ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
     ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
     return(View(album));
 }
示例#18
0
        public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Genre genre)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(genre).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes.  Try again, and if the problem persists, see your system administrator.");
            }

            return(View(genre));
        }
示例#19
0
        public ActionResult Edit(Album album)
        {
            //happy path:当记录状态/模型状态为:有效时
            //sad path:当模型状态:无效时执行当操作和采用路径
            if (ModelState.IsValid)
            {
                //告诉数据上下文,对象在DB已经存在,采用修改模式
                db.Entry(album).State = EntityState.Modified;

                album.Genre  = db.Genres.Where(x => x.GenreId == album.GenreId).FirstOrDefault();
                album.Artist = db.Artists.Where(x => x.ArtistId == album.ArtistId).FirstOrDefault();
                //在数据上下文找那个通过SaveChange方法生成SQL update 命令完成对应记录的更新操作
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
            ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
            return(View(album));
        }
示例#20
0
 public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(album).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
         ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Operation failed. Please contact your system administrator if the problem persists.");
     }
     return(View(album));
 }
示例#21
0
 // PUT api/<controller>/5
 public HttpResponseMessage Put(int id, [FromBody] Album value)
 {
     MusicStoreDB.Entry(value).State = EntityState.Modified;
     return(ToJson(MusicStoreDB.SaveChanges()));
 }