public IHttpActionResult PostNewJoinRequest([FromBody] Joiner newRequest) { if (null != newRequest && null != newRequest.PersonId && null != db.People.Find(newRequest.PersonId) && null != newRequest.WorkoutId && null != db.Workouts.Find(newRequest.WorkoutId) && null == db.Joiners.Find(newRequest.PersonId, newRequest.WorkoutId)) { Workout workout = db.Workouts.Find(newRequest.WorkoutId); if (workout.PersonId == newRequest.PersonId) { newRequest.Status = Response.Accepted; } else { newRequest.Status = Response.Pending; } db.Joiners.Add(newRequest); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewFollow([FromBody] Follower follow) { if (null == db.Followers.Find(follow.FollowerId, follow.FolloweeId) && null != db.People.Find(follow.FollowerId) && null != db.People.Find(follow.FolloweeId)) { db.Followers.Add(follow); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewWorkout([FromBody] Workout newWorkout) { if (null != newWorkout && null != newWorkout.PersonId && null != db.People.Find(newWorkout.PersonId) && null != newWorkout.LocationId && null != db.FitnessLocations.Find(newWorkout.LocationId) && null != newWorkout.Time && DateTime.Compare(DateTime.Now, newWorkout.Time) <= 0 && null != newWorkout.Focus && null != db.Foci.Find(newWorkout.Focus)) { newWorkout.WorkoutId = Guid.NewGuid(); db.Workouts.Add(newWorkout); // A person always joins their own workout Joiner identity = new Joiner { PersonId = newWorkout.PersonId, WorkoutId = newWorkout.WorkoutId, Status = Response.Accepted }; db.Joiners.Add(identity); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewAttend([FromBody] Attends attend) { System.Diagnostics.Debug.WriteLine("creating attends for " + attend.PersonId + " " + attend.LocationId); if (null == db.Attends.Find(attend.PersonId, attend.LocationId) && null != db.People.Find(attend.PersonId) && null != db.FitnessLocations.Find(attend.LocationId)) { db.Attends.Add(attend); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewComment([FromBody] Comment newComment) { newComment.CommentId = Guid.NewGuid(); newComment.Time = DateTime.Now; db.Comments.Add(newComment); db.SaveChanges(); return(Ok()); }
public Session GetNewSession(String PersonId, String Password) { Person person = db.People.Find(PersonId); if (null != person && person.Password == Password) { Session newSession = new Session { SessionId = Guid.NewGuid(), PersonId = PersonId, StartTime = DateTime.Now }; db.Sessions.Add(newSession); db.SaveChanges(); return(newSession); } else { throw new HttpException("Invalid login"); } }
public IHttpActionResult PostNewFocus([FromBody] Focus focus) { if (null != focus && null != focus.FocusId && null == db.Foci.Find(focus.FocusId) && null != focus.Description) { db.Foci.Add(focus); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewLocation([FromBody] FitnessLocation newLocation) { if (null != newLocation && null != newLocation.Name && null != newLocation.Address && null != newLocation.Focus) { newLocation.FitnessLocationId = Guid.NewGuid(); db.FitnessLocations.Add(newLocation); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public IHttpActionResult PostNewPost([FromBody] Post newPost) { if (null != newPost && null != newPost.PersonId && null != db.People.Find(newPost.PersonId) && null != newPost.Text && null != newPost.Focus && null != db.Foci.Find(newPost.Focus)) { newPost.PostId = Guid.NewGuid(); newPost.Time = DateTime.Now; db.Posts.Add(newPost); db.SaveChanges(); return(Ok()); } else { return(Unauthorized()); } }
public Session PostNewPerson([FromBody] Person person) { if (null != person && null != person.PersonId && null == db.People.Find(person.PersonId) && 0 <= person.Age && null != person.Focus && null != db.Foci.Find(person.Focus)) { db.People.Add(person); // A person always follows themselves Follower identity = new Follower { FollowerId = person.PersonId, FolloweeId = person.PersonId }; db.Followers.Add(identity); // Create new session Session newSession = new Session { SessionId = Guid.NewGuid(), PersonId = person.PersonId, StartTime = DateTime.Now }; db.Sessions.Add(newSession); db.SaveChanges(); return(newSession); } else { throw new HttpException("Invalid user creation"); } }