예제 #1
0
        public async Task <IActionResult> GetDailyWork(DateTime?dateFrom, DateTime?dateTo = null, bool filterByAccomplished = false)
        {
            var request = new DailyWorkRequest()
            {
                From = dateFrom.Value,
                To   = dateTo.Value,
                FilterByAccomplishedGoal = filterByAccomplished
            };

            return(ProcessRequest <DailyWorkResponse>(await _api.GetWorkAsync(request, PrimitiveMapperHelper.Map(User.Claims)).ConfigureAwait(false)));
        }
예제 #2
0
        public async Task <BlTResult <DailyWorkResponse> > GetWorkAsync(DailyWorkRequest request, Monster monster)
        {
            try
            {
                IEnumerable <Monsters.DAL.Models.Scare> response = await _repository.GetScaresByDateAsync(request.From, request.To, monster.Id).ConfigureAwait(false);

                if (response.Count() == 0)
                {
                    string msg = $"No work found;";
                    return(new BlTResult <DailyWorkResponse>()
                    {
                        IsSuccess = false, ErrorMsg = msg
                    });
                }

                var dailyWorkResponse = new DailyWorkResponse()
                {
                    DailyWork = new List <DailyWork>()
                };


                DailyWork dailyWork = new DailyWork()
                {
                    Date          = response.First().ScareBegin.Date,
                    DepletedDoors = new List <View.Models.Door>()
                };

                foreach (Monsters.DAL.Models.Scare scare in response)
                {
                    //if we moved to the next day
                    //Wrap the prev day and add it to result
                    if (scare.ScareBegin.Date != dailyWork.Date)
                    {
                        dailyWork.FilledQuota = monster.IsAccomplishedDailyGoal(dailyWork);
                        //Add the day to response if we dont filter by accomplish
                        //or if we do filter by accomplish and the monster accomplished his daily quota that day
                        if (!request.FilterByAccomplishedGoal || dailyWork.FilledQuota)
                        {
                            dailyWorkResponse.DailyWork.Add(dailyWork);
                        }

                        //Start new day
                        dailyWork = new DailyWork()
                        {
                            Date          = scare.ScareBegin.Date,
                            DepletedDoors = new List <View.Models.Door>()
                        };
                    }
                    //add the scare to the day
                    dailyWork.DepletedDoors.Add(PrimitiveMapperHelper.Map(scare.Door));
                }

                return(new BlTResult <DailyWorkResponse>()
                {
                    IsSuccess = true, Data = dailyWorkResponse
                });
            }
            catch (Exception ex)
            {
                string errorMsg = $"Exception thrown trying to get daily work. Error {ex.ToString()}.";
                _logger.LogError(errorMsg);
                return(new BlTResult <DailyWorkResponse>()
                {
                    IsSuccess = false, ErrorMsg = errorMsg
                });
            }
        }