public async Task <IActionResult> PutAsync(int id, [FromBody] UserTask value) { if (_context.UserTasks.Find(id) == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await userManager.GetUserAsync(HttpContext.User); var userId = await userManager.GetUserIdAsync(user); /* * if(value.AplicationUser.Id == userId) * { * * } */ _context.UserTasks.Update(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Birthday,BankNumber,Email,PhoneNumber,Address")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("ID,Title,Description,Status,UserID")] Models.Task task) { if (ModelState.IsValid) { _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserID"] = new SelectList(_context.Users, "ID", "ID", task.UserID); return(View(task)); }
public async Task <bool> LogCreateAction(T entity) { var log = new Log() { ActionType = CREATE, ActionDetails = createMessage.Replace("{entity}", entity.ToString()), Created = DateTime.Now, UserId = 1 }; _userTaskContext.Log.Add(log); return(await _userTaskContext.SaveChangesAsync() > 0); }
public async Task <IActionResult> PatchUser(long id, [FromBody] JsonPatchDocument <User> patchDoc) { if (patchDoc != null) { // Find user on which to apply the update var user = await _context.User.FindAsync(id); // Update only the fields provided in the patchDoc object if (user != null) { patchDoc.ApplyTo(user, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Exists(id)) { return(NotFound()); } else { _logger.LogInformation($"UNABLE TO PATCH USER WITH ID: {id}"); throw; } } } else { return(NotFound(new { message = $"Unable to find TodoItem with id {id}" })); } return(new ObjectResult(user)); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> PatchTaskItem(long id, [FromBody] JsonPatchDocument <TaskItem> patchDoc) { if (patchDoc != null) { var todoItem = await _context.TaskItem.FindAsync(id); if (todoItem != null) { patchDoc.ApplyTo(todoItem, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Exists(id)) { return(NotFound()); } else { _logger.LogInformation($"UNABLE TO PATCH TASK ITEM WITH ID: {id}"); throw; } } } else { return(NotFound(new { message = $"Unable to find TodoItem with id {id}" })); } return(new ObjectResult(todoItem)); } else { return(BadRequest(ModelState)); } }
public async Task <bool> SaveAll() { return(await _userTaskContext.SaveChangesAsync() > 0); }