예제 #1
0
        public IHttpActionResult PutSignupRequest(int activity_id, [FromUri] bool isRescend = false)
        {
            if (!DateRange.WeekendSignupsAreOpen)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, new MethodAccessException("Weekend Signups will be available at 11:30 on Friday."))));
            }

            using (WebhostEntities db = new WebhostAPI.WebhostEntities())
            {
                WebhostUserPrinciple principal = (WebhostUserPrinciple)ActionContext.RequestContext.Principal;
                int id = ((WebhostIdentity)principal.Identity).User.Id;

                WeekendActivity activity = db.WeekendActivities.Find(activity_id);
                if (activity == null)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new InvalidOperationException("Invalid Activity Id."))));
                }

                StudentSignup signup = db.StudentSignups.Find(activity_id, id);

                if (signup == null) // New Signup!
                {
                    signup = new WebhostAPI.StudentSignup()
                    {
                        ActivityId  = activity_id,
                        Attended    = false,
                        IsBanned    = false,
                        IsRescended = isRescend,
                        StudentId   = id,
                        TimeStamp   = DateTime.Now
                    };

                    db.StudentSignups.Add(signup);
                    db.SaveChanges();
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Created, new StudentSignupInfo(activity_id, id), "text/json")));
                }

                signup.IsRescended = isRescend;
                signup.TimeStamp   = DateTime.Now;
                db.SaveChanges();
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new StudentSignupInfo(activity_id, id), "text/json")));
            }
        }
예제 #2
0
        public IHttpActionResult PutOverrideSignup(int activity_id, int student_id, [FromBody] StudentSignupInfo info)
        {
            using (WebhostEntities db = new WebhostAPI.WebhostEntities())
            {
                WeekendActivity activity = db.WeekendActivities.Find(activity_id);
                if (activity == null)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new InvalidOperationException("Invalid Activity Id."))));
                }

                Student student = db.Students.Find(student_id);
                if (student == null)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new InvalidOperationException("Invalid Student Id."))));
                }

                StudentSignup signup = db.StudentSignups.Find(activity_id, student_id);
                if (signup == null) // Create a new one.
                {
                    signup = new WebhostAPI.StudentSignup()
                    {
                        ActivityId  = activity_id,
                        StudentId   = student_id,
                        IsBanned    = info.IsBanned,
                        IsRescended = info.IsRescended,
                        Attended    = false,
                        TimeStamp   = DateTime.Now
                    };
                    db.StudentSignups.Add(signup);
                    db.SaveChanges();
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Created, new StudentSignupInfo(activity_id, student_id), "text/json")));
                }

                signup.IsBanned    = info.IsBanned;
                signup.IsRescended = info.IsRescended;
                signup.TimeStamp   = DateTime.Now;

                db.SaveChanges();
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new StudentSignupInfo(activity_id, student_id), "text/json")));
            }
        }