示例#1
0
        public IHttpActionResult PutRoom(long id, Room room)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != room.Id)
            {
                return(BadRequest());
            }

            db.Entry(room).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public IHttpActionResult SubmitQuestion(SubmitQuestionRequest submitQuestionRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var questionTags = new List <QuestionTag>();

            foreach (var tag in submitQuestionRequest.QuestionTags)
            {
                var t = HackDbContext.QuestionTags.SingleOrDefault(x => x.Tag.Equals(tag.Name));
                if (t != null)
                {
                    questionTags.Add(t);
                }
            }

            var question = new Question(submitQuestionRequest.Title, submitQuestionRequest.Description, questionTags,
                                        DateTime.UtcNow, ApplicationContext.User.UserId);

            HackDbContext.Questions.Add(question);
            HackDbContext.SaveChanges();

            return(Ok(new SubmitQuestionResponse(question.Id)));
        }
示例#3
0
        public IHttpActionResult LeaveQuestion(long id)
        {
            var question = HackDbContext.Questions.SingleOrDefault(x => x.Id == id);

            if (question == null)
            {
                return(InternalServerError());
            }

            question.PeopleEnteredInQuestion = false;
            HackDbContext.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult SubmitOffer(SubmitOfferRequest submitOfferRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var offer = new Offer(submitOfferRequest.Text, DateTime.UtcNow, submitOfferRequest.VideoCallAvailable,
                                  ApplicationContext.User.UserId, submitOfferRequest.QuestionForId);

            HackDbContext.Offers.Add(offer);
            HackDbContext.SaveChanges();

            return(Ok());
        }
示例#5
0
        public IHttpActionResult PollQuestion()
        {
            var questions = HackDbContext.Questions.Where(x => x.UserId == ApplicationContext.User.UserId && x.PeopleEnteredInQuestion);

            var response = new List <PollQuestion>();

            foreach (var question in questions)
            {
                response.Add(new PollQuestion(question.Id, question.Title, question.Description));
                question.PeopleEnteredInQuestion = false;
            }
            HackDbContext.SaveChanges();

            return(Ok(new PollResponse(response)));
        }
        public IHttpActionResult Logout(LogoutRequest logoutRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = HackDbContext.Users.SingleOrDefault(x => x.Username.Equals(logoutRequest.Username));

            if (user == null)
            {
                return(InternalServerError());
            }

            user.Token = string.Empty;
            HackDbContext.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult Login(LoginRequest loginRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = HackDbContext.Users.SingleOrDefault(x => x.Username.Equals(loginRequest.Username) && x.Password.Equals(loginRequest.Password));

            if (user == null)
            {
                return(Unauthorized());
            }

            user.GenerateToken();
            HackDbContext.SaveChanges();

            return(Ok(new LoginResponse(user.Token)));
        }