コード例 #1
0
        public PartialViewResult AjaxAddProduct(int produktNr, int adressId, DateTime date)
        {
            var preAbonnement = new PreAbonnementProdukt
            {
                AddressId = adressId,
                ProduktNr = produktNr,
                StartDate = date,
                EndDate   = null,
                DayOfWeek = (int)date.DayOfWeek,
                Antal     = 1,
                CreatedAt = DateTime.Now,
                CreatedBy = User.Identity.Name,
                Interval  = 0,
                Produkt   = Produkt.AsQuerable().Where(x => x.ProduktNr == produktNr).FirstOrDefault()
            };

            PreAbonnementRepositry.Insert(preAbonnement);
            unitOfWork.Commit();
            var produkt = unitOfWork.Repository <Produkt>().AsQuerable().FirstOrDefault(x => x.ProduktNr == produktNr);

            return(PartialView("_UCDelivery", new CustomerDeliveryDetail
            {
                CustomerDelivery = CustomerDelivery.CreateInstance(preAbonnement),
                AddressId = adressId,
                Date = date
            }));
            //{
            //    Number = 1,
            //    ProduktNumber = produkt.ProduktNr,
            //    Produkt = produkt.Navn,
            //    Id = produkt.Id
            //});
        }
コード例 #2
0
        private IList <CustomerDeliveryAdresses> MergePreAbonnementDeliveries(IList <CustomerDeliveryAdresses> deliveries, DateTime startDate, DateTime endDate, int kundeId)
        {
            //var deliveries = new List<CustomerDeliveryAdresses>();
            foreach (var preAbonnement in PreAbonnementRepositry.AsQuerable().Where(p => p.StartDate >= startDate.Date && p.StartDate <= endDate.Date))
            {
                if (deliveries.Any(m => m.AdressId == preAbonnement.AddressId))
                {
                    if (deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                        .DeliveryWeeks.Any(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate)))
                    {
                        if (deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                            .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                            .DeliverDates.Any(l => l.Date.Date == preAbonnement.StartDate))
                        {
                            if (deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                                .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                                .DeliverDates.First(l => l.Date.Date == preAbonnement.StartDate)
                                .Deliveries.Any(x => x.ProduktNumber == preAbonnement.ProduktNr))
                            {
                                deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                                .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                                .DeliverDates.First(l => l.Date.Date == preAbonnement.StartDate)
                                .Deliveries.First(x => x.ProduktNumber == preAbonnement.ProduktNr).Number += preAbonnement.Antal;


                                preAbonnement.Antal = deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                                                      .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                                                      .DeliverDates.First(l => l.Date.Date == preAbonnement.StartDate)
                                                      .Deliveries.First(x => x.ProduktNumber == preAbonnement.ProduktNr).Number;

                                PreAbonnementRepositry.Update(preAbonnement);
                                // unitOfWork.Commit();
                                continue;
                            }
                            deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                            .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                            .DeliverDates.First(l => l.Date.Date == preAbonnement.StartDate)
                            .Deliveries.Add(CustomerDelivery.CreateInstance(preAbonnement));
                        }
                        else
                        {
                            deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                            .DeliveryWeeks.First(dw => dw.Week == Helpers.TimeTool.GetWeekNumber(preAbonnement.StartDate))
                            .DeliverDates.Add(CustomerDeliverDates.CreateInstance(preAbonnement));
                        }
                    }
                    else
                    {
                        deliveries.First(m => m.AdressId == preAbonnement.AddressId)
                        .DeliveryWeeks.Add(CustomerDeliveryWeek.CreateInstance(preAbonnement));
                    }
                }
                else
                {
                    deliveries.Add(CustomerDeliveryAdresses.CreateInstance(preAbonnement));
                }
            }
            return(deliveries.Distinct().ToList());
        }
コード例 #3
0
        public static IList <CustomerDeliveryAdresses> GetDeliveries(this IRepository <LeveringsProdukt> repository, UnitOfWork unitOfWork,
                                                                     DateTime startDate, DateTime endDate, int kundeId)
        {
            var finalProdukter = new List <LeveringsProdukt>();
            var deliveries     = new List <CustomerDeliveryAdresses>();

            startDate = startDate.Date;
            endDate   = endDate.Date;

            var qleveringer    = unitOfWork.Repository <TurLevering>().AsQuerable().Where(l => l.Ture.Dato >= startDate.Date && l.Ture.Dato <= endDate.Date && l.KundeId == kundeId);
            var leveringMonday = unitOfWork.Repository <TurLevering>().AsQuerable().Max(k => k.Ture.Dato).GetNextMonday().Date;

            var leveringDateMax = leveringMonday > startDate ? leveringMonday : startDate;

            if (qleveringer.Any())
            {
                if (qleveringer.Any(l => l.Ture.Dato > leveringDateMax))
                {
                    leveringDateMax = qleveringer.Max(l => l.Ture.Dato);
                }
                finalProdukter.AddRange(qleveringer.SelectMany(l => l.LeveringProdukts));
            }
            if (qleveringer.Any(l => l.Ture.Dato > leveringDateMax))
            {
                leveringDateMax = qleveringer.Max(l => l.Ture.Dato);
            }


            var maxDate = TimeTool.GetDate(DateTime.Now.Year, TimeTool.GetWeekNumber(leveringDateMax), (int)DayOfWeek.Monday).Date;

            maxDate = maxDate > startDate ? maxDate : startDate;
            if (leveringDateMax > maxDate.Date)
            {
                maxDate = leveringDateMax.Date;
            }

            if (maxDate.Date < endDate.Date)
            {
                List <Abonnementer> abonnementer = unitOfWork.Repository <Abonnementer>().AsQuerable().Where(t => t.Kunde.Id == kundeId).ToList();
                foreach (var tmpway in TimeTool.GetWeekAndYears(maxDate, endDate))
                {
                    var ableveringer = abonnementer.GetLeveringerForService(tmpway.Year, tmpway.Week, unitOfWork.Repository <ProductCustomerSpecialPrice>().AsQuerable());
                    ableveringer.All(abl =>
                    {
                        abl.Ture = new Ture()
                        {
                            TurId     = abl.Ture.TurId,
                            Week      = abl.Ture.Week,
                            Year      = abl.Ture.Year,
                            DayOfWeek = abl.Ture.DayOfWeek,
                            Dato      = TimeTool.GetDate(abl.Ture.Year, abl.Ture.Week, (int)abl.Ture.DayOfWeek)
                        };
                        return(true);
                    });

                    finalProdukter.AddRange(ableveringer.SelectMany(l => l.LeveringProdukts));
                }
            }

            var produkter = finalProdukter.OrderBy(p => p.TurLevering.Ture.Dato).ThenBy(p => p.Produkt.Navn).ToList();

            foreach (var levering in produkter.Where(p => p.TurLevering.Ture.Dato.Date >= startDate.Date && p.TurLevering.Ture.Dato <= endDate.Date))
            {
                if (deliveries.Any(m => m.AdressId == levering.TurLevering.AdresseId))
                {
                    if (deliveries.First(m => m.AdressId == levering.TurLevering.AdresseId)
                        .DeliveryWeeks.Any(dw => dw.Week == levering.TurLevering.Ture.Week))
                    {
                        if (deliveries.First(m => m.AdressId == levering.TurLevering.AdresseId)
                            .DeliveryWeeks.First(dw => dw.Week == levering.TurLevering.Ture.Week)
                            .DeliverDates.Any(l => l.Date.Date == levering.TurLevering.Ture.Dato.Date))
                        {
                            deliveries.First(m => m.AdressId == levering.TurLevering.AdresseId)
                            .DeliveryWeeks.First(dw => dw.Week == levering.TurLevering.Ture.Week)
                            .DeliverDates.First(l => l.Date.Date == levering.TurLevering.Ture.Dato.Date)
                            .Deliveries.Add(CustomerDelivery.CreateInstance(levering));
                        }
                        else
                        {
                            deliveries.First(m => m.AdressId == levering.TurLevering.AdresseId)
                            .DeliveryWeeks.First(dw => dw.Week == levering.TurLevering.Ture.Week)
                            .DeliverDates.Add(CustomerDeliverDates.CreateInstance(levering));
                        }
                    }
                    else
                    {
                        deliveries.First(m => m.AdressId == levering.TurLevering.AdresseId)
                        .DeliveryWeeks.Add(CustomerDeliveryWeek.CreateInstance(levering));
                    }
                }
                else
                {
                    deliveries.Add(CustomerDeliveryAdresses.CreateInstance(levering));
                }
            }
            return(deliveries.Distinct().ToList());
        }