Example #1
0
        public async Task <ItemDiscount> CreateAsync(ItemDiscount obj, bool saveChange = true)
        {
            var item = new ItemDiscount
            {
                Id           = Guid.NewGuid().ToString(),
                CreationDate = DateTime.Now.ToString(),
                Creator      = "Tam",
                FkItem       = obj.FkItem,
                FkDiscount   = obj.FkDiscount,
                IsDeleted    = (int)IsDelete.Normal,
                Value        = obj.Value
            };

            _DbContext.ItemDiscount.Add(item);

            try
            {
                if (saveChange)
                {
                    await _DbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(item);
        }
Example #2
0
        public async Task <ItemDiscount> UpdateAsync(ItemDiscount obj, bool saveChange = true)
        {
            var item = await _DbContext.ItemDiscount.FirstOrDefaultAsync(h => h.Id == obj.Id);

            try
            {
                if (saveChange)
                {
                    await _DbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(item);
        }
    /// <summary>
    /// Adds custom discount to the given shopping cart item if another product is also in the cart.
    /// </summary>
    /// <param name="item">Shoppping cart item</param>
    /// <param name="discounts">Discounts of the shopping cart item</param>
    /// <param name="anotherItemName">SKU number of another product which must be in the cart to apply the discount</param>
    private void AddDiscountForBundledPurchase(ShoppingCartItemInfo item, List<IItemDiscount> discounts, string anotherItemName)
    {
        // Add discount to the product if product B is also in the cart
        ShoppingCartItemInfo itemB = GetShoppingCartItem(item.ShoppingCartObj, anotherItemName);
        if (itemB != null)
        {
            // Create custom 20% discount
            ItemDiscount discount = new ItemDiscount()
            {
                ItemDiscountID = "DISCOUNT_AB",
                ItemDiscountDisplayName = string.Format("Discount for bundled purchase of product '{0}' and '{1}'", item.SKUObj.SKUName, itemB.SKUObj.SKUName),
                ItemDiscountValue = 20,
                ItemDiscountedUnits = itemB.CartItemUnits
            };

            // Add custom discount to discounts to be applied to the product
            discounts.Add(discount);
        }
    }
Example #4
0
        static void Main(string[] args)
        {
            Player player1 = new Player();

            player1.Id            = 1;
            player1.NationalityId = "********";
            player1.FirstName     = "Alierk";
            player1.LastName      = "Küçük";
            player1.BirthDate     = new DateTime(1986, 03, 05);
            player1.PlayerName    = "meSSiaS";
            player1.Money         = 150;

            Item item1 = new Item();

            item1.ItemName  = "Armor";
            item1.ItemPrice = 100;



            SellingManager sellingManager = new SellingManager();
            PlayerManager  playerManager  = new PlayerManager(new MernisServiceAdapter());

            playerManager.Save(player1);
            //playerManager.Update("MESSIAS", player1);
            //playerManager.Delete(player1);
            sellingManager.Buy(item1, player1);
            sellingManager.Sell(item1, player1);
            BaseDiscountManager discountManager = new DiscountManager();

            discountManager.MakeDiscount(0.50, item1);
            BaseDiscountManager discountManager1 = new BirthDayDiscountManager(player1, new DiscountAdapter());

            discountManager1.MakeDiscount(0.75, item1);
            sellingManager.Buy(item1, player1);
            ItemDiscount itemDiscount = new ItemDiscount();

            itemDiscount.DiscountName = "Yeni Yıl";
            itemDiscount.DiscountRate = 0.75;
            itemDiscount.item         = item1;
            BaseDiscountManager itemDiscountManager = new ItemDiscountManager();

            itemDiscountManager.MakeDiscount(itemDiscount.DiscountRate, itemDiscount.item);
        }
    /// <summary>
    /// Adds custom discount to the given shopping cart item if user is member of specified role.
    /// </summary>
    /// <param name="item">Shoppping cart item</param>
    /// <param name="discounts">Discounts of the shopping cart item</param>
    /// <param name="roleName">Name of the role the user must be member of to apply the discount</param>
    private void AddDiscountForVIPRole(ShoppingCartItemInfo item, List <IItemDiscount> discounts, string roleName)
    {
        UserInfo user = item.ShoppingCartObj.UserInfoObj;

        // Add discount to the product if user is member of the role
        if ((user != null) && user.IsInRole(roleName, item.ShoppingCartObj.SiteName))
        {
            // Create custom 10% discount
            ItemDiscount discount = new ItemDiscount()
            {
                ItemDiscountID          = "DISCOUNT_VIP",
                ItemDiscountDisplayName = string.Format("Discount for VIP customers", item.SKUObj.SKUName),
                ItemDiscountValue       = 10,
                ItemDiscountedUnits     = item.CartItemUnits
            };

            // Add custom discount to discounts to be applied to the product
            discounts.Add(discount);
        }
    }
    /// <summary>
    /// Adds custom discount to the given shopping cart item if another product is also in the cart.
    /// </summary>
    /// <param name="item">Shoppping cart item</param>
    /// <param name="discounts">Discounts of the shopping cart item</param>
    /// <param name="anotherItemName">SKU number of another product which must be in the cart to apply the discount</param>
    private void AddDiscountForBundledPurchase(ShoppingCartItemInfo item, List <IItemDiscount> discounts, string anotherItemName)
    {
        // Add discount to the product if product B is also in the cart
        ShoppingCartItemInfo itemB = GetShoppingCartItem(item.ShoppingCartObj, anotherItemName);

        if (itemB != null)
        {
            // Create custom 20% discount
            ItemDiscount discount = new ItemDiscount()
            {
                ItemDiscountID          = "DISCOUNT_AB",
                ItemDiscountDisplayName = string.Format("Discount for bundled purchase of product '{0}' and '{1}'", item.SKUObj.SKUName, itemB.SKUObj.SKUName),
                ItemDiscountValue       = 20,
                ItemDiscountedUnits     = itemB.CartItemUnits
            };

            // Add custom discount to discounts to be applied to the product
            discounts.Add(discount);
        }
    }
        public async Task <InvoiceDto> Handle(AddInvoiceCommand request, CancellationToken cancellationToken)
        {
            var invoice = _mapper.Map <Invoice>(request.Invoice);
            var session = await _context.Sessions.FirstOrDefaultAsync(s => !s.IsClosed);

            if (invoice.Table != null && !invoice.IsPaid)
            {
                var table = await _context.Tables.FirstOrDefaultAsync(s => s.Id == invoice.TableId);

                table.IsBeingUsed = true;
            }

            await _context.Invoices.AddAsync(invoice);

            foreach (var item in request.Invoice.Items)
            {
                var invoiceItem = new InvoiceItem
                {
                    InvoiceId = invoice.Id,
                    ItemId    = item.Id,
                    Quantity  = item.Quantity,
                    Value     = item.Value
                };
                await _context.InvoiceItems.AddAsync(invoiceItem);

                if (invoice.IsPaid)
                {
                    var itemDb = await _context.Items.FirstOrDefaultAsync(i => i.Id == item.Id);

                    itemDb.CurrentQuantity -= item.Quantity;
                    if (itemDb.CurrentQuantity <= 0)
                    {
                        itemDb.IsOutOfStock = true;
                    }
                }

                foreach (var discount in item.Discounts)
                {
                    var itemDiscount = new ItemDiscount
                    {
                        ItemId        = item.Id,
                        DiscountId    = discount.Id,
                        Value         = discount.Value,
                        InvoiceItemId = invoiceItem.Id
                    };
                    await _context.ItemDiscounts.AddAsync(itemDiscount);
                }
            }

            foreach (var discount in request.Invoice.Discounts)
            {
                var invoiceDiscount = new InvoiceDiscount
                {
                    InvoiceId  = invoice.Id,
                    DiscountId = discount.Id,
                    Value      = discount.Value
                };
                await _context.InvoiceDiscounts.AddAsync(invoiceDiscount);
            }

            if (invoice.IsPaid)
            {
                session.Revenue       += invoice.TotalPrice;
                session.ExpectedMoney += invoice.TotalPrice + invoice.Tip;
                session.Tip           += invoice.Tip;
            }

            if (await _context.SaveChangesAsync() > 0)
            {
                var invoiceToReturn = await _mediator.Send(new GetInvoiceQuery(invoice.Id));

                return(invoiceToReturn);
            }
            return(null);
        }
    /// <summary>
    /// Adds custom discount to the given shopping cart item if user is member of specified role.
    /// </summary>
    /// <param name="item">Shoppping cart item</param>
    /// <param name="discounts">Discounts of the shopping cart item</param>
    /// <param name="roleName">Name of the role the user must be member of to apply the discount</param>
    private void AddDiscountForVIPRole(ShoppingCartItemInfo item, List<IItemDiscount> discounts, string roleName)
    {
        UserInfo user = item.ShoppingCartObj.UserInfoObj;

        // Add discount to the product if user is member of the role
        if ((user != null) && user.IsInRole(roleName, item.ShoppingCartObj.SiteName))
        {
            // Create custom 10% discount
            ItemDiscount discount = new ItemDiscount()
            {
                ItemDiscountID = "DISCOUNT_VIP",
                ItemDiscountDisplayName = string.Format("Discount for VIP customers", item.SKUObj.SKUName),
                ItemDiscountValue = 10,
                ItemDiscountedUnits = item.CartItemUnits
            };

            // Add custom discount to discounts to be applied to the product
            discounts.Add(discount);
        }
    }
        public async Task <bool> Handle(UpdateInvoiceCommand request, CancellationToken cancellationToken)
        {
            var invoice = await _context.Invoices.FirstOrDefaultAsync(i => i.Id == request.Invoice.Id);

            _mapper.Map(request.Invoice, invoice);
            var session = await _context.Sessions.FirstOrDefaultAsync(s => !s.IsClosed);

            var table = await _context.Tables.FirstOrDefaultAsync(s => s.Id == invoice.TableId);

            if (!invoice.IsPaid)
            {
                table.IsBeingUsed = true;
            }
            else
            {
                table.IsBeingUsed = false;
            }

            var invoiceItems = _context.InvoiceItems.Where(i => i.InvoiceId == request.Invoice.Id).ToList();

            foreach (var item in request.Invoice.Items)
            {
                if (invoice.IsPaid)
                {
                    var itemDb = await _context.Items.FirstOrDefaultAsync(i => i.Id == item.Id);

                    itemDb.CurrentQuantity -= item.Quantity;
                    if (itemDb.CurrentQuantity <= 0)
                    {
                        itemDb.IsOutOfStock = true;
                    }
                }
                if (!item.IsAdded)
                {
                    var invoiceItem = new InvoiceItem
                    {
                        InvoiceId = invoice.Id,
                        ItemId    = item.Id,
                        Quantity  = item.Quantity,
                        Value     = item.Value
                    };

                    foreach (var discount in item.Discounts)
                    {
                        var itemDiscount = new ItemDiscount
                        {
                            ItemId        = item.Id,
                            DiscountId    = discount.Id,
                            Value         = discount.Value,
                            InvoiceItemId = invoiceItem.Id
                        };
                        await _context.ItemDiscounts.AddAsync(itemDiscount);
                    }
                    await _context.InvoiceItems.AddAsync(invoiceItem);
                }
            }

            foreach (var discount in request.Invoice.Discounts)
            {
                if (!discount.IsAdded)
                {
                    var invoiceDiscount = new InvoiceDiscount
                    {
                        InvoiceId  = invoice.Id,
                        DiscountId = discount.Id,
                        Value      = discount.Value
                    };
                    await _context.InvoiceDiscounts.AddAsync(invoiceDiscount);
                }
            }

            if (invoice.IsPaid)
            {
                session.Revenue       += invoice.TotalPrice;
                session.ExpectedMoney += invoice.TotalPrice + invoice.Tip;
                session.Tip           += invoice.Tip;
            }

            if (await _context.SaveChangesAsync() > 0)
            {
                return(true);
            }

            return(false);
        }
Example #10
0
 public async Task SendItemDiscount(ItemDiscount itemDiscount)
 {
     await Clients.Others.SendAsync("ReceiveItemDiscount", itemDiscount);
 }