Пример #1
0
        public async Task <ActionResult> Edit(EditSquareSetPieceViewModel squareSetPieceViewModel)
        {
            if (ModelState.IsValid)
            {
                // upload the new image
                var storage = new StorageFacade();
                var image   = squareSetPieceViewModel.UpdatedImage;
                var url     = storage.Store(image.FileName, image.InputStream, User.Identity.GetUserId());

                // update the db
                var setPiece = await _db.SquareSetPieces.FirstAsync(o => o.Id == squareSetPieceViewModel.Id);

                setPiece.ImageUrl = url;

                await _db.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = squareSetPieceViewModel.Id }));
            }

            return(View(squareSetPieceViewModel));
        }
Пример #2
0
        // GET: SquareSetPieces/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SquareSetPiece squareSetPiece = await _db.SquareSetPieces.FindAsync(id);

            if (squareSetPiece == null)
            {
                return(HttpNotFound());
            }

            var squareSetPieceViewModel = new EditSquareSetPieceViewModel
            {
                Id = squareSetPiece.Id,
                CurrentImageUrl = squareSetPiece.ImageUrl,
                SquareSetId     = squareSetPiece.SquareSetId
            };

            return(View(squareSetPieceViewModel));
        }