public IHttpActionResult Register([FromBody] UserRegistrationFormData data)
        {
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }
            user_repository.CreateNewUser(data);
            return(Ok());
        }
Example #2
0
        public IHttpActionResult ContestRegistration(int contest_id, [FromBody] ContestRegistrationFormData registration_form_data)
        {
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            try{
                // todo replace user id 2 with the user sending the request
                contest_repository.RegisterUserForContest(contest_id, 2, registration_form_data);
                return(Ok());
            }
            catch (ObjectNotFoundException e) {
                return(NotFound());
            }
            catch (InvalidOperationException e) {
                return(InternalServerError(e));
            }
        }
Example #3
0
        public IHttpActionResult Login(Login credentials)
        {
            this.user_service = new UserService();

            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            bool success = user_service.LoginUser(credentials.Username, credentials.Password);

            if (success)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Example #4
0
        public IHttpActionResult UpdateUser([FromBody] UserProfileUpdateForm data, int id)
        {
            if (!user_service.IsAuthorizedToEditUesrProfile(id))
            {
                return(Unauthorized());
            }

            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            try{
                user_repository.UpdateUser(id, data);
                return(Ok());
            }
            catch (ObjectNotFoundException e) {
                return(NotFound());
            }
        }
Example #5
0
        public IHttpActionResult Submit(int problem_id, [FromBody] SubmissionFormData data)
        {
            if (!user_service.IsAuthorizedToSubmitToProblem(problem_id))
            {
                return(Unauthorized());
            }

            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }


            try{
                submission_repository.CreateProblemSubmission(problem_id, data);
                return(Ok());
            }
            catch (ObjectNotFoundException e) {
                return(NotFound());
            }
        }
Example #6
0
        public IHttpActionResult ContestProblemSubmit(int contest_id, int problem_no, [FromBody] SubmissionFormData submission_data)
        {
            if (!user_service.IsAuthorizedToSubmitToContest(contest_id))
            {
                return(Unauthorized());
            }

            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            try{
                contest_submission_repository.CreateSubmission(contest_id, problem_no, submission_data);
                return(Ok());
            }
            catch (InvalidOperationException e) {
                return(BadRequest("Can not submit to contest that has ended"));
            }
            catch (ObjectNotFoundException e) {
                return(NotFound());
            }
        }
        public IHttpActionResult EditAnnouncement(int id, [FromBody] AnnouncementFormData data)
        {
            if (!user_service.IsAuthorizedToEditAnnouncements(id))
            {
                return(Unauthorized());
            }

            // for preflight requests
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }

            announcement_repository.UpdateAnnouncement(id, data);
            return(Ok());
        }
        public IHttpActionResult Create([FromBody] AnnouncementFormData data)
        {
            if (!user_service.IsAuthorizedToCreateAnnouncements())
            {
                return(Unauthorized());
            }

            // for preflight requests
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }

            var announcement = announcement_repository.createAnnouncement(data);

            return(Ok(new AnnouncementsResponseData(announcement)));
        }