Exemplo n.º 1
0
        public async Task <ActionResult <BiryaniModel> > PostBiryaniModel([FromForm] BiryaniModel biryaniModel)
        {
            try
            {
                biryaniModel.Image = await SaveImage(biryaniModel.ImageFile);

                _context.biryaniModels.Add(biryaniModel);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(StatusCode(201));
            // return CreatedAtAction("GetBiryaniModel", new { id = biryaniModel.Id }, biryaniModel);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutBiryaniModel(int id, [FromForm] BiryaniModel biryaniModel)
        {
            if (id != biryaniModel.Id)
            {
                return(BadRequest());
            }
            try
            {
                if (biryaniModel.ImageFile != null)
                {
                    DeleteImage(biryaniModel.Image);
                    biryaniModel.Image = await SaveImage(biryaniModel.ImageFile);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

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

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

            return(NoContent());
        }