Esempio n. 1
0
        public async Task <IActionResult> PutGift([FromRoute] int id, [FromBody] Gift gift)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != gift.GiftId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("GiftId,Title,Description,CreationDate,GenderId")] GiftViewModel giftViewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(giftViewModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(giftViewModel));
        }