public IHttpActionResult PutPorfolioStock(int id, PorfolioStock porfolioStock) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != porfolioStock.StockId) { return(BadRequest()); } db.Entry(porfolioStock).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PorfolioStockExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(User userParam, string password = null) { User user = dbContext.Users.Find(userParam.Id); if (user == null) { throw new AppException("User not found"); } if (userParam.UserName != user.UserName) { // username has changed so check if the new username is already taken if (dbContext.Users.Any(x => x.UserName == userParam.UserName)) { throw new AppException("UserName " + userParam.UserName + " is already taken"); } } // update user properties user.FirstName = userParam.FirstName; user.LastName = userParam.LastName; user.UserName = userParam.UserName; // update password if it was entered if (!string.IsNullOrWhiteSpace(password)) { //byte[] passwordHash, passwordSalt; //CreatePasswordHash(password, out passwordHash, out passwordSalt); //user.PasswordHash = passwordHash; //user.PasswordSalt = passwordSalt; user.Password = password; } dbContext.Entry(user).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); }