public ShopView(Shop shop) { ShopRepository shopRepository; AddressRepository addressRepository; CityRepository cityRepository; StreetRepository streetRepository; StreetTypeRepository streetTypeRepository; shopRepository = new ShopRepository(); addressRepository = new AddressRepository(); cityRepository = new CityRepository(); streetRepository = new StreetRepository(); streetTypeRepository = new StreetTypeRepository(); this.Id = shop.Id; this.Name = shop.Name; this.BookDeliveryCost = shop.BookDeliveryCost; this.Address = (Address)addressRepository.FindById(this.Id); this.City = (City)cityRepository.FindById(this.Address.CityId); this.Street = (Street)streetRepository.FindById(this.Address.StreetId); this.StreetType = (StreetType) streetTypeRepository.FindById(this.Street.StreetTypeId); }
public ActionResult _SearchShop(Shop shop) { Payment payment; Basket basket; BasketService basketService; shop = (Shop)this._shopRepository.FindById(shop.Id); ViewData["isShopSelected"] = true; shop.Address = (Address)this._addressRepository.FindById(shop.Id); return RedirectToAction("SelectShop", shop); }
//Обновление корзины. Обновление переменной информации книги. //Необходимо рассчитать стоимость доставки, а также обновить //пересчитать книги. //Стоимость книг и стоимость доставки хранятся отдельно public Basket ShopProcessing(Basket basket, Shop shop) { List<BasketItem> basketItems; BookVariableInfo bookVariableInfo; Int32 allBasketItemCount, itemSum; BasketRepository basketRepository; BasketItemRepository basketItemRepository; BookVariableInfoRepository bookVariableInfoRepository; if (basket != null && shop != null) { basketRepository = (BasketRepository) this._basketRepository; basketItemRepository = (BasketItemRepository) this._basketItemRepository; bookVariableInfoRepository = (BookVariableInfoRepository) this._bookVariableInfoRepository; basketItems = (List<BasketItem>) basketItemRepository.FindAllByBasket(basket.Id); allBasketItemCount = (from item in basketItems select item.ItemCount).Sum(); //Обновление книжной информации в БД var basketItemGroups = from item in basketItems group item by item.BookVariableInfoId into basketGroup select basketGroup; foreach (var groupp in basketItemGroups) { bookVariableInfo = (BookVariableInfo) this._bookVariableInfoRepository.FindById(groupp.Key); itemSum = (from s in groupp.ToList() select s.ItemCount).Sum(); bookVariableInfo.ProductCount -= itemSum; bookVariableInfoRepository.Edit(bookVariableInfo); } //BaseService._db.SaveChanges(); //Обновление корзины basket.DeliveryCost = shop.BookDeliveryCost * allBasketItemCount; basketRepository.Edit(basket); return basket; } else { throw new Exception("Корзина или магазин не заданы!"); } }
public ActionResult SelectShop(Shop shop) { Basket basket; IList<Shop> shops; PaymentView paymentView; UrlGenerator urlGenerator; Payment payment, dbPayment; W1Payment w1Payment, dbW1Payment; W1PaymentView w1PaymentView; Individual individual; BasketService basketService; IndividualRepository individualRepository; PaymentRepository paymentRepository; PaymentService paymentService; //Необходимо вызвать UrlGenerator в любом Post-методе контроллера, //иначе Request и Url поля не будут доступны. //В будующем нужно исправить! urlGenerator = new UrlGenerator(this.Request, this.Url); basketService = new BasketService(); paymentRepository = new PaymentRepository(); paymentService = new PaymentService(); individualRepository = new IndividualRepository(); //---- shop = (Shop)this._shopRepository.FindById(shop.Id); //для адреса basket = basketService.GetBasket(User.Identity.Name); //Вычитаем заказанныек книги из BookVariableInfo и //обвновляем Basket basketService.ShopProcessing(basket, shop); shop.Address = (Address)this._addressRepository.FindById(shop.Id); //-- //Создание платежной формы W1Payment individual = (Individual)individualRepository .FindIndividualByUserProfileName(User.Identity.Name); w1Payment = new W1Payment(); w1Payment.WMI_PAYMENT_AMOUNT = paymentService.DecimalCounting( basket.TotalAmount, shop.BookDeliveryCost); w1Payment.WMI_DESCRIPTION = paymentService.MakeDescription(basket.Id); dbW1Payment = paymentService.MakeW1Payment(w1Payment); //добавление payment и w1Payment payment = new Payment() { Id = dbW1Payment.WMI_PAYMENT_NO, ShopId = shop.Id, IndividualId = individual.Id }; dbPayment = paymentService.AddPayment(payment, w1Payment); payment.Id = dbPayment.Id; //Перемещение заказов из корзины в платеж и очистка корзины basketService.BasketToPaymentMigration(basket, payment); //-Создали представление для отображения w1Payment и передачи его в POST w1PaymentView = new W1PaymentView(dbW1Payment);//payment, basket); return RedirectToAction("BasketPay", w1PaymentView);//shop); //payment); }