public async Task <IHttpActionResult> PutLocation_Status(int id, Location_Status location_Status) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != location_Status.LocationStatusID) { return(BadRequest()); } db.Entry(location_Status).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Location_StatusExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public object loginUser(User userInput) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); try { var hash = GenerateHash(ApplySalt(userInput.UserPassword)); User user = db.Users.Where(x => x.UserName == userInput.UserName && x.UserPassword == hash).FirstOrDefault(); if (user != null) { Guid guid = Guid.NewGuid(); user.SessionID = guid.ToString(); if (userInput.ContainerID != null) { user.ContainerID = userInput.ContainerID; } if (userInput.Container != null) { Container con = db.Containers.Where(x => x.ContainerID == userInput.ContainerID).FirstOrDefault(); if (con != null) { user.Container = con; } } db.Entry(user).State = EntityState.Modified; // Checks if anything from the user here is diffent from the user in the db db.SaveChanges(); toReturn.sessionID = guid.ToString(); } else { toReturn.Error = "Incorrect Username or Password"; } } catch { toReturn.Error = "Login Unsuccesful"; } return(toReturn); }
public object updateSupplier(Supplier SupplierUpdate) { db.Configuration.ProxyCreationEnabled = false; Supplier objectSupplier = new Supplier(); dynamic toReturn = new ExpandoObject(); var id = SupplierUpdate.SupplierID; try { objectSupplier = db.Suppliers.Where(x => x.SupplierID == id).FirstOrDefault(); if (objectSupplier != null) { objectSupplier.SupName = SupplierUpdate.SupName; objectSupplier.SupCell = SupplierUpdate.SupCell; objectSupplier.SupEmail = SupplierUpdate.SupEmail; objectSupplier.SupStreetNr = SupplierUpdate.SupStreetNr; objectSupplier.SupStreet = SupplierUpdate.SupStreet; objectSupplier.SupCode = SupplierUpdate.SupCode; objectSupplier.SupSuburb = SupplierUpdate.SupSuburb; db.Entry(objectSupplier).State = EntityState.Modified; db.SaveChangesAsync(); toReturn.Message = "Update Successful"; } else { toReturn.Message = "Record Not Found"; } } catch (Exception) { toReturn.Message = "Update UnSuccessful"; } return(toReturn); }