Ejemplo n.º 1
0
        /// <summary>
        /// Метод получает задания в статусе "В аукционе".
        /// </summary>
        /// <returns>Список заданий в аукционе.</returns>
        public async Task <GetTaskResultOutput> LoadAuctionTasks()
        {
            try
            {
                GetTaskResultOutput resultTasks  = new GetTaskResultOutput();
                IEnumerable         auctionTasks = await(from tasks in _postgre.Tasks
                                                         join categories in _postgre.TaskCategories on tasks.CategoryCode equals categories.CategoryCode
                                                         join statuses in _postgre.TaskStatuses on tasks.StatusCode equals statuses.StatusCode
                                                         join users in _postgre.Users on tasks.OwnerId equals users.Id
                                                         where statuses.StatusName.Equals(StatusTask.AUCTION)
                                                         select new
                {
                    tasks.CategoryCode,
                    tasks.CountOffers,
                    tasks.CountViews,
                    tasks.OwnerId,
                    tasks.SpecCode,
                    categories.CategoryName,
                    tasks.StatusCode,
                    statuses.StatusName,
                    TaskBegda = string.Format("{0:f}", tasks.TaskBegda),
                    TaskEndda = string.Format("{0:f}", tasks.TaskEndda),
                    tasks.TaskTitle,
                    tasks.TaskDetail,
                    tasks.TaskId,
                    TaskPrice = string.Format("{0:0,0}", tasks.TaskPrice),
                    tasks.TypeCode,
                    users.UserName
                })
                                                   .OrderBy(o => o.TaskId)
                                                   .ToListAsync();

                // Приводит к типу коллекции GetTaskResultOutput.
                foreach (object task in auctionTasks)
                {
                    string     jsonString = JsonSerializer.Serialize(task);
                    TaskOutput result     = JsonSerializer.Deserialize <TaskOutput>(jsonString);

                    // Считает кол-во ставок к заданию, либо проставит 0.
                    int countResponds = await _postgre.Responds
                                        .Where(r => r.TaskId == result.TaskId)
                                        .Select(r => r.RespondId)
                                        .CountAsync();

                    result.CountOffers = countResponds > 0 ? countResponds : 0;

                    resultTasks.Tasks.Add(result);
                }

                return(resultTasks);
            }

            catch (Exception ex)
            {
                Logger _logger = new Logger(_db, ex.GetType().FullName, ex.Message.ToString(), ex.StackTrace);
                await _logger.LogCritical();

                throw new Exception(ex.Message.ToString());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> LoadAuctionTasks()
        {
            GetTaskResultOutput auctionTasks = await _taskService.LoadAuctionTasks();

            return(Ok(auctionTasks));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Метод получает задания определенного статуса.
        /// </summary>
        /// <param name="status">Название статуса.</param>
        /// <param name="userName">Логин пользователя.</param>
        /// <returns>Список заданий с определенным статусом.</returns>
        public async Task <GetTaskResultOutput> GetStatusTasks(string status, string userName)
        {
            try
            {
                var result = new GetTaskResultOutput();

                var userId = await GetUserByName(userName);

                var tasks = string.IsNullOrEmpty(status) ? throw new ArgumentNullException() :
                                  await(from task in _postgre.Tasks
                                        join categories in _postgre.TaskCategories on task.CategoryCode equals categories.CategoryCode
                                        join statuses in _postgre.TaskStatuses on task.StatusCode equals statuses.StatusCode
                                        where statuses.StatusName.Equals(status)
                                        where task.OwnerId.Equals(userId)
                                        select new
                {
                    task.CategoryCode,
                    task.CountOffers,
                    task.CountViews,
                    task.OwnerId,
                    task.SpecCode,
                    categories.CategoryName,
                    task.StatusCode,
                    statuses.StatusName,
                    TaskBegda = string.Format("{0:f}", task.TaskBegda),
                    TaskEndda = string.Format("{0:f}", task.TaskEndda),
                    task.TaskTitle,
                    task.TaskDetail,
                    task.TaskId,
                    TaskPrice = string.Format("{0:0,0}", task.TaskPrice),
                    task.TypeCode,
                    UserName = userName
                })
                                  .OrderBy(o => o.TaskId)
                                  .ToListAsync();

                foreach (var t in tasks)
                {
                    var jsonString = JsonSerializer.Serialize(t);
                    var jResult    = JsonSerializer.Deserialize <TaskOutput>(jsonString);

                    result.Tasks.Add(jResult);
                }

                return(result);
            }

            catch (ArgumentNullException ex)
            {
                Logger _logger = new Logger(_db, ex.GetType().FullName, ex.Message.ToString(), ex.StackTrace);
                await _logger.LogError();

                throw new ArgumentNullException($"Не передан статус {ex.Message}");
            }

            catch (Exception ex)
            {
                Logger _logger = new Logger(_db, ex.GetType().FullName, ex.Message.ToString(), ex.StackTrace);
                await _logger.LogCritical();

                throw new Exception(ex.Message.ToString());
            }
        }