示例#1
0
        public async Task <IActionResult> PutFishPrawnsSnacksModel(int id, [FromForm] FishPrawnsSnacksModel fishPrawnsSnacksModel)
        {
            if (id != fishPrawnsSnacksModel.Id)
            {
                return(BadRequest());
            }
            try
            {
                if (fishPrawnsSnacksModel.ImageFile != null)
                {
                    DeleteImage(fishPrawnsSnacksModel.Image);
                    fishPrawnsSnacksModel.Image = await SaveImage(fishPrawnsSnacksModel.ImageFile);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            _context.Entry(fishPrawnsSnacksModel).State = EntityState.Modified;

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

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <FishPrawnsSnacksModel> > PostFishPrawnsSnacksModel([FromForm] FishPrawnsSnacksModel fishPrawnsSnacksModel)
        {
            try
            {
                fishPrawnsSnacksModel.Image = await SaveImage(fishPrawnsSnacksModel.ImageFile);

                _context.fishPrawnsSnacks.Add(fishPrawnsSnacksModel);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(StatusCode(201));
            // return CreatedAtAction("GetFishPrawnsSnacksModel", new { id = fishPrawnsSnacksModel.Id }, fishPrawnsSnacksModel);
        }