コード例 #1
0
 public AttributeGroupServer(IUnitofWork unit)
 {
     this.unit = unit;
     ClassRep  = unit.Repository <Classfiy>();
     AtRep     = unit.Repository <Entities.Attribute>();
     ValueRep  = unit.Repository <AttributeValue>();
     BrandRep  = unit.Repository <Brand>();
     GroupRep  = unit.Repository <AttributeGroup>();
 }
コード例 #2
0
ファイル: UserinfoService.cs プロジェクト: Y2N55G8/Shopping
        //IRepository<UserType> typeRep;
        //IRepository<RoleGroup> RGroupRep;

        public UserinfoService(IUnitofWork unit)
        {
            this.unit    = unit;
            this.userRep = unit.Repository <Userinfo>();
            //this.typeRep = unit.Repository<UserType>();
            //this.RGroupRep = unit.Repository<RoleGroup>();
        }
コード例 #3
0
ファイル: PaymentService.cs プロジェクト: jkgoel/Skinet
        public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId)
        {
            StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"];
            var basket = await _basketRepository.GetBasketAsync(basketId);

            if (basket == null)
            {
                return(null);
            }

            var shippingPrice = 0m;

            if (basket.DeliveryMethodId.HasValue)
            {
                var deliveryMethod = await _unitofWork.Repository <DeliveryMethod>().GetByIdAsync(basket.DeliveryMethodId.Value);

                shippingPrice = deliveryMethod.Price;
            }
            foreach (var item in basket.Items)
            {
                var productItem = await _unitofWork.Repository <Product>().GetByIdAsync(item.Id);

                if (item.Price != productItem.Price)
                {
                    item.Price = productItem.Price;
                }
            }

            var           service = new PaymentIntentService();
            PaymentIntent intent;

            if (string.IsNullOrEmpty(basket.PaymentIntentId))
            {
                var options = new PaymentIntentCreateOptions
                {
                    Amount             = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100,
                    Currency           = "inr",
                    PaymentMethodTypes = new List <string> {
                        "card"
                    }
                };

                intent = await service.CreateAsync(options);

                basket.PaymentIntentId = intent.Id;
                basket.ClientSecret    = intent.ClientSecret;
            }
            else
            {
                var options = new PaymentIntentUpdateOptions
                {
                    Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100,
                };
                await service.UpdateAsync(basket.PaymentIntentId, options);
            }

            await _basketRepository.UpdatetBasketAsync(basket);

            return(basket);
        }
コード例 #4
0
ファイル: OrderService.cs プロジェクト: jkgoel/Skinet
        public async Task <Order> CreateOrderAync(string buyerEmail, int deliveryMethodId, string basketId, Address shippingAddress)
        {
            var basket = await _basketRepo.GetBasketAsync(basketId);

            var items = new List <OrderItem>();

            foreach (var item in basket.Items)
            {
                var productItem = await _unitofWork.Repository <Product>().GetByIdAsync(item.Id);

                var itemOrdered = new ProductItemOrdered(productItem.Id, productItem.Name, productItem.PictureUrl);
                var orderItem   = new OrderItem(itemOrdered, productItem.Price, item.Quantity);
                items.Add(orderItem);
            }

            var deliveryMethod = await _unitofWork.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId);

            var subtotal = items.Sum(item => item.Price * item.Quantity);

            var spec          = new OrderByPaymentIntentIdSpecification(basket.PaymentIntentId);
            var existingOrder = await _unitofWork.Repository <Order>().GetEntityWithSpec(spec);

            if (existingOrder != null)
            {
                _unitofWork.Repository <Order>().Delete(existingOrder);
                await _paymentService.CreateOrUpdatePaymentIntent(basket.PaymentIntentId);
            }

            var order = new Order(items, buyerEmail, shippingAddress, deliveryMethod, subtotal, basket.PaymentIntentId);

            _unitofWork.Repository <Order>().Add(order);

            var result = await _unitofWork.Complete();

            if (result <= 0)
            {
                return(null);
            }

            return(order);
        }
コード例 #5
0
        public async Task <Order> CreateOrderAsync(string buyerEmail, int deliveryMethodId, string basketId,
                                                   Address shippingAddress)
        {
            // get basket from the repo
            var basket = await _basketRepo.GetBasketAsync(basketId);

            // get items from the product repo
            var items = new List <OrderItem>();

            foreach (var item in basket.Items)
            {
                var productItem = await _unitofWork.Repository <Product>().GetByIdAsync(item.Id);

                var itemOrdered = new ProductItemOrdered(productItem.Id, productItem.Name,
                                                         productItem.PictureUrl);
                var orderItem = new OrderItem(itemOrdered, productItem.Price, item.Quantity);
                items.Add(orderItem);
            }
            // get delivery method from repo
            var deliveryMethod = await _unitofWork.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId);

            // calc subtotal
            var subtotal = items.Sum(item => item.Price * item.Quantity);

            // create order
            var order = new Order(items, buyerEmail, shippingAddress, deliveryMethod, subtotal);

            _unitofWork.Repository <Order>().Add(order);

            // save to db
            var result = await _unitofWork.Complete();

            if (result <= 0)
            {
                return(null);
            }

            //delete basket
            await _basketRepo.DeleteBasketAsync(basketId);

            // return order
            return(order);
        }
コード例 #6
0
 public RoleGroupService(IUnitofWork unit)
 {
     this.unit  = unit;
     RGroupRep  = unit.Repository <RoleGroup>();
     contactRep = unit.Repository <RoleContact>();
 }
コード例 #7
0
 public UserCenter(IUnitofWork unit)
 {
     this.unit  = unit;
     addressRep = unit.Repository <UserAddress>();
 }
コード例 #8
0
 public ShangpinServer(IUnitofWork unit)
 {
     this.unit = unit;
     ShangRep  = unit.Repository <Shangpin>();
     SARep     = unit.Repository <ShangpinAttribute>();
 }
コード例 #9
0
 public List <Product> ReturnAllProducts()
 {
     return(_UnitofWork.Repository <Product>().GetProducts());
 }
コード例 #10
0
 public RoleService(IUnitofWork unit)
 {
     this.unit = unit;
     roleRep   = unit.Repository <Role>();
 }
コード例 #11
0
 public CuxiaoService(IUnitofWork unit)
 {
     this.unit = unit;
     cuxiaoRep = unit.Repository <Cuxiao>();
 }