public async Task <IActionResult> PutListItem(int id, ListItem listItem) { if (id != listItem.Id) { return(BadRequest()); } _context.Entry(listItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ListItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ListItem> > PostListItem(ListItem item) { _context.ListItems.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetListItem), new { id = item.Id }, item)); }
public async Task <IActionResult> PutConnectionList([FromRoute] long id, [FromBody] ConnectionModel conItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != conItem.Id) { return(BadRequest()); } _context.Entry(conItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConnectionItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <string> Add(UserProfileToken token) { _context.UserProfileTokens.Add(token); await _context.SaveChangesAsync(); return(token.Token); }
public async Task <IActionResult> Create([Bind("ID,Description,CreatedDate")] TheList theList) { if (ModelState.IsValid) { _context.Add(theList); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(theList)); }
//post: Create public async Task <IActionResult> Create(TaskItem list) { //var id = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]); if (list != null) { list.UserId = UserId; _context.Tasks.Add(list); await _context.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task<IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { string password = HashPassword(model.Password, model.Email); User user = await _db.Users.FirstOrDefaultAsync(u => u.Email == model.Email); if (user == null) { user = _db.Users.Add(new User { Email = model.Email, Password = password }).Entity; await _db.SaveChangesAsync(); await Authenticate(user); // аутентификация return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } } return View(model); }