コード例 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] User userUpdateValue)
        {
            try
            {
                userUpdateValue.EntryTime = DateTime.Now;

                var userToEdit = await _context.User
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(m => m.ID == id);

                if (userToEdit == null)
                {
                    return(NotFound("Could not update user as it was not Found"));
                }
                else
                {
                    _context.Update(userUpdateValue);
                    await _context.SaveChangesAsync();

                    return(Json("Updated user - " + userUpdateValue.Name));
                }
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");
                return(NotFound("User not Found"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Put(int id, [FromBody] Leaf leafUpdateValue)
        {
            try
            {
                leafUpdateValue.ItemCreatedDate = DateTime.Now;

                var leafToEdit = await _context.Leaf
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(m => m.ID == id);

                if (leafToEdit == null)
                {
                    return(NotFound("Could not update leaf as it was not Found"));
                }
                else
                {
                    _context.Update(leafUpdateValue);
                    await _context.SaveChangesAsync();

                    return(Ok("Updated leaf - " + leafUpdateValue.ItemName));
                }
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");
                return(NotFound("Leaf not Found"));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Update([Bind("ID,Name")] Users userUpdateValue)
        {
            try
            {
                userUpdateValue.EntryTime = DateTime.Now;
                _context.Update(userUpdateValue);
                await _context.SaveChangesAsync();

                return(Ok(userUpdateValue));
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");
                return(NotFound("User not Found"));
            }
        }