Exemplo n.º 1
0
        public async Task <(DateTime start, DateTime end)> StartExam(string login, string code)
        {
            var exam = await GetExamByCode(code, true);

            if (exam != null)
            {
                var savedExam = await ExamApproachesRepo.GetAsync(exam.Id, login);

                if (savedExam == null)
                {
                    ExamApproache item = new ExamApproache
                    {
                        ExamId = exam.Id,
                        Start  = DateTime.Now,
                        End    = DateTime.Now.AddMinutes(exam.DurationMinutes).AddSeconds(30),
                        Login  = login
                    };
                    var result = await ExamApproachesRepo.AddAsync(item);

                    if (result != null)
                    {
                        return(result.Start, result.End);
                    }
                }
                else
                {
                    return(savedExam.Start, savedExam.End);
                }
            }
            return(new DateTime(2000, 1, 1), new DateTime(2000, 1, 1));
        }
        public virtual async Task <IActionResult> Put(int examId, ExamApproache item)
        {
            if (examId != item.ExamId)
            {
                return(BadRequest());
            }
            await repo.UpdateAsync(item);

            try
            {
                await repo.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!repo.FindBy(a => a.ExamId == examId).Any())
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
        public async Task <ActionResult <ExamApproache> > Post(ExamApproache item)
        {
            await repo.AddAsync(item);

            await repo.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { examId = item.ExamId, login = item.Login }, item));
        }
Exemplo n.º 4
0
        public async Task <DateTime> AddAsync(ExamApproache item)
        {
            try
            {
                await dbSetExamApproache.AddAsync(item);

                return(item.Start);
            }
            catch (Exception ex)
            {
                return(new DateTime(2000, 1, 1));
            }
        }
Exemplo n.º 5
0
        public async Task <bool> UpdateAsync(ExamApproache item)
        {
            try
            {
                await Task.Run(() => dbSetExamApproache.Update(item));

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async virtual Task <bool> UpdateAsync(ExamApproache item)
        {
            try
            {
                var response = await ExamApproachesClient.PutAsJsonAsync($"{uri}/{item.ExamId}", item);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, System.Reflection.MethodBase.GetCurrentMethod().ToString());
                return(false);
            }
        }
        public async virtual Task <ExamApproache> AddAsync(ExamApproache item)
        {
            try
            {
                var response = await ExamApproachesClient.PostAsJsonAsync($"{uri}/Post", item);

                if (response.IsSuccessStatusCode)
                {
                    return(item);
                }
                return(null);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, System.Reflection.MethodBase.GetCurrentMethod().ToString());
                return(null);
            }
        }