public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Cloth = await _db.Clothes.FindAsync(id);

            if (Cloth != null)
            {
                // Remove image from AWS
                try
                {
                    _awsS3Service.DeleteFile(Cloth.PictureUri);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("S3 Delete", e.Message);
                }
                _db.Clothes.Remove(Cloth);
                await _db.SaveChangesAsync();
            }

            return(RedirectToPage("./Dashboard"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            var ClothToUpdate = await _db.Clothes.FindAsync(id);

            if (ClothToUpdate == null)
            {
                return(NotFound());
            }

            if (Upload != null)
            {
                try
                {
                    ClothToUpdate.PictureUri = await _awsS3Service.UploadFile(Upload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("S3 Upload", e.Message);
                }
            }

            if (await TryUpdateModelAsync <Clothing>(
                    ClothToUpdate,
                    "ClothItem",
                    s => s.ClothName, s => s.PictureUri, s => s.IsClean, s => s.CategoryId))
            {
                await _db.SaveChangesAsync();

                return(RedirectToPage("../Dashboard"));
            }

            return(Page());
        }