public IHttpActionResult PutManufacturer(int id, Manufacturer manufacturer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != manufacturer.ManufacturerId) { return(BadRequest()); } db.Entry(manufacturer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ManufacturerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.CategoryId) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "UserId,Email,Password,Role,ApiKey")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public void putProduct(int id, Product product) { Product updatedProduct = getProductById(id); updatedProduct.Name = product.Name; updatedProduct.Price = product.Price; updatedProduct.InventoryCount = product.InventoryCount; updatedProduct.CreatedDate = product.CreatedDate; updatedProduct.LastModifiedDate = product.LastModifiedDate; updatedProduct.CategoryId = product.CategoryId; updatedProduct.ManufacturerId = product.ManufacturerId; db.Entry(updatedProduct).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }
public HttpResponseMessage GetApiKey(string email, string password) { var getUser = repo.getApiKey(email, password); var user = db.Users.First(x => x.Email == email); if (user != null) { if (Crypto.VerifyHashedPassword(user.Password, password)) { FormsAuthentication.SetAuthCookie(user.Email, true); } } if (getUser == null) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Email or Password")); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (getUser.ApiKey == null) { try { getUser.ApiKey = GetApiKey(); db.Entry(getUser).State = EntityState.Modified; //db.Entry(getUser).CurrentValues.SetValues(getUser); db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Failed to save API key to database")); } } var response = Request.CreateResponse(HttpStatusCode.OK); response.Headers.Add("xcmps383authenticationid", getUser.UserId.ToString()); response.Headers.Add("xcmps383authenticationkey", getUser.ApiKey); return(Request.CreateResponse(HttpStatusCode.OK, TheDTOFactory.Create(getUser.ApiKey, getUser.UserId))); // return response; }
public ActionResult Edit([Bind(Include = "UserId,Email,Password,Role")] User userRole) { if (ModelState.IsValid) { userRole.Role = userRole.Role; db.Entry(userRole).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } // else //{ // ModelState.AddModelError("", "You need to be admin Bro to change my data"); // @ViewBag.Message = "You need to be admin to edit"; // } return(View(userRole)); }