예제 #1
0
        public async Task <IActionResult> practicequestion([FromQuery] AnswerDTO ques)
        {
            User user = _helperService.GetUser();

            if (user == null)
            {
                return(Ok(new ErrorDto {
                    StatusCode = StatusCodes.Status401Unauthorized, Message = "Unauthorized"
                }));
            }
            else
            {
                var acc = await _context.PracticeCandidate.Where(x => (x.CandidateId == user.Id) && (x.QuestionId == ques.questionid)).SingleOrDefaultAsync();

                PracticeCandidate ac = new PracticeCandidate();
                if (acc == null)
                {
                    ac.CandidateId = Convert.ToInt32(user.Id);
                    ac.QuestionId  = ques.questionid;
                    ac.Status      = 1;
                    _context.PracticeCandidate.Add(ac);
                }
                else
                {
                    _context.Entry <PracticeCandidate>(acc).State = EntityState.Detached;
                    ac.Id = acc.Id;
                    _context.PracticeCandidate.Attach(ac);
                    ac.Status = 1;
                }
                await _context.SaveChangesAsync();

                return(await PQuestion(ques.questionid));
            }
        }
예제 #2
0
        public async Task <IActionResult> practiceanswer(IFormFile file, [FromForm] AnswerDTO answer)
        {
            User user = _helperService.GetUser();

            if (user == null)
            {
                return(Ok(new ErrorDto {
                    StatusCode = StatusCodes.Status401Unauthorized, Message = "Unauthorized"
                }));
            }
            else
            {
                try
                {
                    if (file.Length > 0)
                    {
                        string   fileName = ""; fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                        FileInfo fi       = new FileInfo(fileName);
                        string   fileN    = _helperService.RandomString(8, true) + fi.Extension;
                        string   strurl   = _helperService.GetMediaUrl(user.UserGuid.ToString()) + "/" + fileN;
                        string   fullPath = Path.Combine(_helperService.GetFilePath(user.UserGuid.ToString()), fileN);
                        using (var stream = new FileStream(fullPath, FileMode.Create))
                        {
                            file.CopyTo(stream);
                        }
                        var acc = await _context.PracticeCandidate.Where(x => (x.CandidateId == user.Id) && (x.QuestionId == answer.questionid)).SingleOrDefaultAsync();

                        PracticeCandidate ac = new PracticeCandidate();
                        if (acc == null)
                        {
                            ac.VideoFile   = fileN;
                            ac.UploadedOn  = DateTime.Now;
                            ac.CandidateId = Convert.ToInt32(user.Id);
                            ac.QuestionId  = answer.questionid;
                            ac.Status      = 2;
                            _context.Add(ac);
                        }
                        else
                        {
                            _context.Entry <PracticeCandidate>(acc).State = EntityState.Detached;
                            ac.Id = acc.Id;
                            _context.PracticeCandidate.Attach(ac);
                            ac.VideoFile   = fileN;
                            ac.CandidateId = Convert.ToInt32(user.Id);
                            ac.QuestionId  = answer.questionid;
                            ac.UploadedOn  = DateTime.Now;
                            ac.Status      = 2;
                        }
                        await _context.SaveChangesAsync();

                        return(await PQuestion(answer.questionid));
                    }
                    else
                    {
                        return(Ok(new { StatusCode = StatusCodes.Status200OK, message = "Error Submitting data.", result = "" }));
                    }
                }
                catch (System.Exception ex)
                {
                    return(Ok(new { StatusCode = StatusCodes.Status417ExpectationFailed, message = ex.Message }));
                }
            }
        }