public HttpResponseMessage PostUpdateRequest(RequestsWtihLinkedData rwld) { if (ModelState.IsValid) { request currentReq = (from req in _db.requests.Include("facilities").Include("roomsPref").Include("roomsAlloc") where req.id == rwld.id select req).FirstOrDefault(); currentReq.facilities.Clear(); currentReq.roomsPref.Clear(); _db.SaveChanges(); var updateReq = UpdateRequestObject(rwld, currentReq); _db.Entry(currentReq).CurrentValues.SetValues(updateReq); _db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, updateReq); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = updateReq.id })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
// PUT api/TestDept/5 public HttpResponseMessage Putdepartment(string id, department department) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != department.code) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(department).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage PostChangePassword(Models.PasswordModel pm) { Authentication auth = new Authentication(); string deptCode = GetAuthorisedDepartment().code; bool correctPassword = auth.ValidateUser(deptCode, pm.currentPassword); if (correctPassword) { if (ModelState.IsValid) { department dept = (from d in _db.departments where d.code == deptCode select d).FirstOrDefault(); string deptSalt = dept.salt; string newDeptPassword = auth.HashPassword(pm.newPassword, deptSalt); dept.hashedPassword = newDeptPassword; _db.Entry(dept).CurrentValues.SetValues(dept); _db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, pm); response.Headers.Location = new Uri(Url.Link("DefaultApi", null)); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.OK, "Invalid Password")); } }