public IHttpActionResult CreatePreferences(Preferences pref) { MatchMakerEntities db = new MatchMakerEntities(); MatchMakerEntities dbContext = new MatchMakerEntities(); if (db.People.Find(pref.person_id) != null && dbContext.Preferences.Find(pref.person_id) == null) { db.Preferences.Add(pref); } else { return(BadRequest("Preferences with given person_id already exists")); } try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); db.SaveChanges(); } return(Ok()); }
public IHttpActionResult UpdatePreferences(int id, Preferences preferences) { MatchMakerEntities db = new MatchMakerEntities(); var prefs = db.Preferences.Where(x => x.person_id == id).FirstOrDefault(); if (prefs == null) { return(BadRequest("No preferences exists for given ID")); } else { prefs.fieldofinterest1 = preferences.fieldofinterest1; prefs.fieldofinterest2 = preferences.fieldofinterest2; prefs.fieldofinterest3 = preferences.fieldofinterest3; prefs.position1 = preferences.position1; prefs.position2 = preferences.position2; prefs.position3 = preferences.position3; prefs.technology1 = preferences.technology1; prefs.technology2 = preferences.technology2; prefs.technology3 = preferences.technology3; } db.SaveChanges(); return(Ok("Updated")); }
public IHttpActionResult DeletePreferences(int id) { MatchMakerEntities db = new MatchMakerEntities(); People pl = new People(); Preferences pr = new Preferences(); if (id <= 0) { return(BadRequest("not a valid id")); } else if (db.People.Find(id) == null) { return(BadRequest("no account with given id exists")); } else { pl = db.People.Find(id); pr = db.Preferences.Where(x => x.person_id == id).FirstOrDefault(); if (pr == null) { return(BadRequest("no preferences for given account")); } else { db.Preferences.Remove(pr); } db.SaveChanges(); } return(Ok("preferences deleted")); }
public IHttpActionResult Update(int id, [FromBody] People people) { MatchMakerEntities dbContext = new MatchMakerEntities(); if (people != null || people.GetType().GetProperties().Any()) { var entityMatch = dbContext.People.FirstOrDefault(p => p.person_id == id); entityMatch.firstname = people.firstname; entityMatch.lastname = people.lastname; entityMatch.course = people.course; entityMatch.description = people.description; entityMatch.usertype = people.usertype; try { dbContext.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); dbContext.SaveChanges(); } } else { return(NotFound()); } return(Ok()); }
public IHttpActionResult Create(People people) { MatchMakerEntities dbContext = new MatchMakerEntities(); if (people != null || people.GetType().GetProperties().Any()) { people.regdate = DateTime.Now.Date; var pwd = people.password; people.passwordhash = pwd.GetHashCode(); people.password = null; dbContext.People.Add(people); } else { return(NotFound()); } try { dbContext.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); dbContext.SaveChanges(); } return(Ok()); }
public IHttpActionResult CreatePeople([FromBody] int?id, string firstname, string lastname, string course, string description, bool usertype) { MatchMakerEntities dbContext = new MatchMakerEntities(); People people = new People(); people.firstname = firstname; people.lastname = lastname; people.course = course; people.description = description; people.usertype = usertype; if (people != null || people.GetType().GetProperties().Any()) { dbContext.People.Add(people); } try { dbContext.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); dbContext.SaveChanges(); } return(Ok()); }
public IHttpActionResult Login(People people) { MatchMakerEntities dbContext = new MatchMakerEntities(); var entityMatch = dbContext.People.First(p => p.email == people.email); var clientHash = people.password.GetHashCode(); if (clientHash == entityMatch.passwordhash && people.email == entityMatch.email) { return(Ok(entityMatch)); } else { return(BadRequest("Password hash did not match with given information")); } }
public IHttpActionResult GetAll() { MatchMakerEntities db = new MatchMakerEntities(); List <People> peopleList = new List <People>(); People pl = new People(); Preferences pr = new Preferences(); var people = from p in db.People orderby p.person_id select p; foreach (var person in people) { peopleList.Add(person); } return(Ok(peopleList)); }