예제 #1
0
        public async Task <ActionResult <IEnumerable <StatisticsModel> > > GetDeliveriesForStatisticsOfCourier(string d11, string d22)
        {
            try
            {
                DateTime d1 = new DateTime(Convert.ToInt64(d11));
                DateTime d2 = new DateTime(Convert.ToInt64(d22));
                List <StatisticsModel> list = new List <StatisticsModel>();
                var users = userRepository.GetUsersIdsWithCourierRole();
                foreach (var item in users)
                {
                    StatisticsModel sm = new StatisticsModel {
                        UserID = item
                    };
                    var user = await userRepository.GetUserAsync(item);

                    sm.ImePrezime = user.FirstName + " " + user.LastName;

                    sm.Procenat = user.Procenat;
                    var deliveries = deliveryRepository.GetAllDeliveries().Where(x => (x.DeliveryStatus == 4) && (x.CourierID == item) && (x.CreateTime.Date >= d1.Date) && (x.CreateTime.Date <= d2.Date));

                    foreach (var delivery in deliveries)
                    {
                        sm.Promet += Convert.ToDouble(delivery.DeliveryPrice);
                        switch (delivery.PaymentTypeID)
                        {
                        //kes
                        case 1:
                            sm.PrometCash += delivery.DeliveryPrice;
                            break;

                        //faktura
                        case 2:
                            sm.PrometFaktura += delivery.DeliveryPrice;
                            break;

                        //kupon
                        case 3:
                            sm.PrometCupon += delivery.DeliveryPrice;
                            break;

                        default:
                            break;
                        }
                    }
                    sm.BrojDostava     = deliveries.Count();
                    sm.PrihodOdPrometa = sm.Promet * sm.Procenat / 100;
                    list.Add(sm);
                }

                if (list != null)
                {
                    return(Ok(list));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }