Пример #1
0
        public async Task <IActionResult> VoteDoctorAnswer([Bind("DoctorId")] DoctorVote dv, [FromForm] int questionId)
        {
            if (!User.IsInRole("Doctor"))
            {
                Question q = await _context.Questions.FirstOrDefaultAsync(m => m.Id == questionId);

                if (q.Status == QuestionStatus.INACTIVE)
                {
                    return(BadRequest(new APIResponse {
                        Status = APIStatus.Failed, Data = null
                    }));
                }
                dv.UserId = int.Parse(_userManager.GetUserId(User));
                _context.DoctorVotes.Add(dv);
                q.Status = QuestionStatus.INACTIVE;
                _context.Questions.Update(q);
                await _context.SaveChangesAsync();

                return(Ok(new APIResponse {
                    Status = APIStatus.Success, Data = null
                }));
            }
            return(BadRequest(new APIResponse {
                Status = APIStatus.Failed, Data = null
            }));
        }
Пример #2
0
        public async Task <IActionResult> VoteDoctorRoom([Bind("DoctorId")] DoctorVote dv, [FromForm] int sessionId)
        {
            if (User.IsInRole("Customer"))
            {
                Session s = await _context.Sessions.FirstOrDefaultAsync(m => m.Id == sessionId);

                if (s.Status == SessionStatus.PENDING)
                {
                    return(BadRequest(new APIResponse {
                        Status = APIStatus.Failed, Data = null
                    }));
                }
                dv.UserId = int.Parse(_userManager.GetUserId(User));
                _context.DoctorVotes.Add(dv);
                await _context.SaveChangesAsync();

                return(Ok(new APIResponse {
                    Status = APIStatus.Success, Data = null
                }));
            }
            return(BadRequest(new APIResponse {
                Status = APIStatus.Failed, Data = null
            }));
        }