예제 #1
0
        public async Task <ActionResult <RotiNaanModel> > PostRotiNaanModel([FromForm] RotiNaanModel rotiNaanModel)
        {
            try
            {
                rotiNaanModel.Image = await SaveImage(rotiNaanModel.ImageFile);

                _context.rotiNaans.Add(rotiNaanModel);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(StatusCode(201));
            // return CreatedAtAction("GetRotiNaanModel", new { id = rotiNaanModel.Id }, rotiNaanModel);
        }
예제 #2
0
        public async Task <IActionResult> PutRotiNaanModel(int id, [FromForm] RotiNaanModel rotiNaanModel)
        {
            if (id != rotiNaanModel.Id)
            {
                return(BadRequest());
            }
            try
            {
                if (rotiNaanModel.ImageFile != null)
                {
                    DeleteImage(rotiNaanModel.Image);
                    rotiNaanModel.Image = await SaveImage(rotiNaanModel.ImageFile);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            _context.Entry(rotiNaanModel).State = EntityState.Modified;

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

            return(NoContent());
        }