Beispiel #1
0
        /// <summary>
        /// Service method responsible for handling HTTP Get verb of GetSentSMS DTO request
        /// </summary>
        /// <param name="request">an object of GetSentSMS DTO type</param>
        /// <returns>an object of GetSentSMSResponse DTO type</returns>
        public async Task <GetSentSMSResponse> Get(GetSentSMS request)
        {
            var filteredList = await _smsRepository.FilterByDateAsync(
                DateTime.Parse(request.DateTimeFrom),
                DateTime.Parse(request.DateTimeTo),
                request.Skip,
                request.Take);

            var sentSMSResponses = new List <SentSMSResponse>();

            foreach (var item in filteredList)
            {
                var itemCountry = (await _countryRepository.GetByMobileCodeAsync(item.MobileCountryCode));

                decimal itemPrice = itemCountry != null ? itemCountry.PricePerSMS : 0;

                sentSMSResponses.Add(new SentSMSResponse
                {
                    DateTime = item.SendDate.ToString("yyyy-MM-ddTHH:mm:ss"),
                    Mcc      = item.MobileCountryCode,
                    From     = item.Sender,
                    To       = item.Receiver,
                    Price    = decimal.Parse(itemPrice.ToString().TrimEnd('0').TrimEnd('.'))
                });
            }

            return(new GetSentSMSResponse
            {
                TotalCount = sentSMSResponses.Count,
                Items = sentSMSResponses,
                State = StateEnum.Success
            });
        }
        public async Task <GetSentSMSResponse> Get(GetSentSMS request)
        {
            var take = request.Take ?? 10;
            var skip = request.Skip ?? 0;
            var from = DateTime.SpecifyKind(Convert.ToDateTime(request.DateTimeFrom), DateTimeKind.Utc);
            var to   = DateTime.SpecifyKind(Convert.ToDateTime(request.DateTimeTo), DateTimeKind.Utc);
            Expression <Func <Sms, bool> > dateTimeCondition = sms => from <= sms.CreatedAt && sms.CreatedAt <= to;

            var totalSmsRecords = await Db.CountAsync <Sms>(dateTimeCondition);

            var smsRecords = await Db.SelectAsync(Db.From <Sms>()
                                                  .Where(dateTimeCondition)
                                                  .Skip(skip)
                                                  .Limit(take)
                                                  );

            return(new GetSentSMSResponse()
            {
                Items = smsRecords,
                TotalCount = totalSmsRecords
            });
        }