예제 #1
0
        public async Task <ActionResult <LwdzDTO> > PostLwdz(LwdzDTO lwdzDTO)
        {
            var lwdz = new Lwdz
            {
                Name = lwdzDTO.Name,
                Pwd  = lwdzDTO.Pwd
            };

            _context.Lwdzs.Add(lwdz);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLwdz", new { id = lwdz.ID }, LwdzToDTO(lwdz)));
        }
예제 #2
0
        public async Task <IActionResult> PutLwdz(long id, LwdzDTO lwdzDTO)
        {
            if (id != lwdzDTO.ID)
            {
                return(BadRequest());
            }

            var lwdz = await _context.Lwdzs.FindAsync(id);

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

            lwdz.Name = lwdzDTO.Name;
            lwdz.Pwd  = lwdzDTO.Pwd;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!LwdzExists(id))
            {
                return(NotFound());
            }

            //_context.Entry(lwdzDTO).State = EntityState.Modified;

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

            return(NoContent());
        }