public IActionResult User_EditPassword(int id, [FromBody] PasswordReset psw_reset) { // verify that the user is either admin or is requesting their own data if (!HelperMethods.ValidateIsUserOrAdmin(_httpContextAccessor, _context, id, _keyAndIV)) { ErrorMessage error = new ErrorMessage("Invalid User", "Caller can only access their information."); return(new UnauthorizedObjectResult(error)); } // get user from db User user = _context.Users.Single(a => a.ID == id); // if password is valid then we change it and update db if (ValidatePassword(psw_reset.Current_Password, user.Password)) { user.Password = HelperMethods.ConcatenatedSaltAndSaltedHash(psw_reset.New_Password); _context.Update(user); _context.SaveChanges(); return(Ok()); } else { ErrorMessage error = new ErrorMessage("Invalid Password", "Your current password does not match."); return(new BadRequestObjectResult(error)); } }
public async Task <Category> Put(Category category) { _context.Update(category); await _context.SaveChangesAsync(); return(category); }
// method for updating entity in database public async Task <Product> Put(Product product) { _context.Update(product); await _context.SaveChangesAsync(); return(product); }
public async Task <IActionResult> Edit(string id, [Bind("Id,UserId,Content,CreationDate")] Post post) { if (id != post.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(post); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(post.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", post.UserId); return(View(post)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ExpertiseLevel")] Skill skill) { if (id != skill.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(skill); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SkillExists(skill.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(skill)); }
public async Task <Orders> Update(Orders value) { var editedEntity = _context.Set <Orders>().FirstOrDefault(e => e.OrderSKU == value.OrderSKU); if (editedEntity != null) { editedEntity.Address = value.Address; editedEntity.City = value.City; editedEntity.Stage = value.Stage; editedEntity.OrderDate = value.OrderDate; editedEntity.OrderEmail = value.OrderEmail; editedEntity.OrderZipCode = value.OrderZipCode; editedEntity.Phone = value.Phone; editedEntity.TotalAmount = value.TotalAmount; _context.Update(editedEntity); await _context.SaveChangesAsync(); return(value); } else { return(null); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,FullName,Address,Email,MobilePhoneNumber")] Contact contact) { if (id != contact.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contact); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(contact.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task<Categories> Update(Categories value) { var editedEntity = _context.Set<Categories>().FirstOrDefault(e => e.Id== value.Id); editedEntity = value; _context.Update(editedEntity); await _context.SaveChangesAsync(); return value; }
public async Task <OrderDetails> Update(OrderDetails value) { var editedEntity = _context.Set <OrderDetails>().FirstOrDefault(e => e.DetailId == value.DetailId); editedEntity = value; _context.Update(editedEntity); await _context.SaveChangesAsync(); return(value); }
public IActionResult Save(Usuario oUsuario) { List <Usuario> _oUsuarios = new List <Usuario>(); _context.Update(oUsuario); _context.SaveChanges(); _oUsuarios = _context.Usuario.ToList(); if (_oUsuarios.Count == 0) { return(NotFound("Nenhuma lista encontrada.")); } return(Ok(_oUsuarios)); }
// generate our refresh token with expiration public static RefreshToken GenerateRefreshToken(User user, APIContext context) { // Create the refresh token RefreshToken refreshToken = new RefreshToken() { UserID = user.ID, Token = GenerateRefreshToken(), Expiration = DateTime.UtcNow.AddDays(1).ToString() // 1 day for reresh tokens }; // Add it to the list of of refresh tokens for the user user.RefreshTokens.Add(refreshToken); // Update the user along with the new refresh token context.Update(user); return(refreshToken); }
// generate our refresh token with expiration public static RefreshToken GenerateRefreshToken(User user, APIContext context) { // Create the refresh token RefreshToken refreshToken = new RefreshToken() { UserID = user.ID, Token = HelperMethods.EncryptStringToBytes_Aes(GenerateRefreshToken(), HelperMethods.GetUserKeyAndIV(user.ID)), Expiration = HelperMethods.EncryptStringToBytes_Aes(DateTime.UtcNow.AddDays(200).ToString(), HelperMethods.GetUserKeyAndIV(user.ID)) // 200 days for reresh tokens }; // Add it to the list of of refresh tokens for the user user.RefreshTokens.Add(refreshToken); // Update the user along with the new refresh token context.Update(user); context.SaveChanges(); // save last return(refreshToken); }
public string User_EditPassword(int id, [FromBody] string passwordJson) { // verify that the user is either admin or is requesting their own data if (!HelperMethods.ValidateIsUserOrAdmin(_httpContextAccessor, _context, id)) { Response.StatusCode = 401; return(JObject.FromObject(new ErrorMessage("Invalid User", "id accessed: " + id.ToString(), "Caller can only access their information.")).ToString()); } JObject json = null; // might want Json verification as own function since all will do it.. we will see try { json = JObject.Parse(passwordJson); } catch (Exception ex) { Response.StatusCode = 400; ErrorMessage error = new ErrorMessage("Invalid Json", passwordJson, ex.Message); return(JObject.FromObject(error).ToString()); } try { User user = _context.Users.Single(a => a.ID == id); // if password is valid then we change it and update db if (ValidatePassword(json["current_password"].ToString(), user.Password)) { user.Password = HelperMethods.ConcatenatedSaltAndSaltedHash(json["new_password"].ToString()); _context.Update(user); _context.SaveChanges(); } else { Response.StatusCode = 401; return(JObject.FromObject(new ErrorMessage("Invalid Password", json["current_password"].ToString(), "n/a")).ToString()); } } catch (Exception ex) { Response.StatusCode = 500; return(JObject.FromObject(new ErrorMessage("Failed to update with new password", "n/a", ex.Message)).ToString()); // don't continue to send password back and forth in messages } return(JObject.Parse(SuccessMessage._result).ToString()); }
public string UpdateLista(Listacompras lista) { try { if (lista != null) { _contexto.Update(lista); _contexto.SaveChanges(); return("Lista alterada com sucesso!"); } else { return("Lista inválida!"); } } catch (Exception) { return("Não foi possível se comunicar com a base de dados!"); } }
public string UpdateUsuario(Usuario usuario) { try { if (usuario != null) { _contexto.Update(usuario); _contexto.SaveChanges(); return("Usuário alterado com sucesso!"); } else { return("Usuário inválido!"); } } catch (Exception) { return("Não foi possível se comunicar com a base de dados!"); } }
public string UpdateProduto(Produto produto) { try { if (produto != null) { _contexto.Update(produto); _contexto.SaveChanges(); return("Produto alterado com sucesso!"); } else { return("Produto inválido!"); } } catch (Exception ex) { return("Não foi possível se comunicar com a base de dados! " + ex); } }
public async Task <Products> Update(Products value) { var editedEntity = _context.Set <Products>().FirstOrDefault(e => e.ProductSKU == value.ProductSKU); if (editedEntity != null) { editedEntity.Name = value.Name; editedEntity.OriginalPrice = value.OriginalPrice; editedEntity.Size = value.Size; editedEntity.ShortDescription = value.ShortDescription; editedEntity.ActualPrice = value.ActualPrice; editedEntity.LongDescription = value.LongDescription; editedEntity.IsLive = value.IsLive; editedEntity.ImagePath = value.ImagePath; editedEntity.ThumbnailPath = value.ThumbnailPath; _context.Update(editedEntity); await _context.SaveChangesAsync(); return(value); } return(null); }
public void Update(Item item) { _context.Update(item); _context.SaveChanges(); }
public void Update(Address address) { _context.Update(address); _context.SaveChanges(); }
public void Update(User user) { _context.Update(user); _context.SaveChanges(); }
public void Update(Donation donation) { _context.Update(donation); _context.SaveChanges(); }