private async void OnDelete(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var canDelete = await DisplayDeleteAlertAsync();

                if (canDelete)
                {
                    var discountLogic = new DiscountLogic(_dbContext);
                    await discountLogic.DeleteAsync(DiscountBindProp.Id);

                    DiscountBindProp.Status = Status.Deleted;
                    var param = new NavigationParameters();
                    param.Add(Keys.DISCOUNT, DiscountBindProp);
                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #2
0
        public void DiscountCalculate(int inputPrice, int inputAmount, double expected)
        {
            var sut    = new DiscountLogic();
            var result = sut.DiscountCalculate(inputAmount, inputPrice);

            Assert.Equal(expected, result);
        }
        public async Task ProcessOrderAsync()
        {
            var rule = RuleBuilder.CreateRuleImp(SampleRules.GetOrCreateSampleRule());

            if (rule == null)
            {
                throw new InvalidOperationException("Rule object is not defined.");
            }
            var context = new OrderDiscountContext(Order.Model);
            await context.ExecuteAsync(rule);

            Discounts = context.GetOrderDiscounts();
            Total     = DiscountLogic.GetOrderTotalAmount(Order.Model, Discounts);
            LogInfo("Order has been processed successfully.");
        }
        public ActionResult Index(DelDiscModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            DiscountLogic nwdsc = new DiscountLogic();
            string        res   = nwdsc.delete(Int32.Parse(model.DiscountID));

            // Don't do this in production!


            // user authN failed
            ModelState.AddModelError("", res);
            return(View());
        }
Exemple #5
0
        public ActionResult Index(NewDiscModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            DiscountLogic nwdsc = new DiscountLogic();
            string        res   = nwdsc.addnew(Int32.Parse(model.UserID), Int32.Parse(model.GoodID), Int32.Parse(model.percents));

            // Don't do this in production!


            // user authN failed
            ModelState.AddModelError("", res);
            return(View());
        }
        private async void GetAllInvoice()
        {
            try
            {
                var itemLogic        = new ItemLogic(_dbContext);
                var discountLogic    = new DiscountLogic(_dbContext);
                var invoiceLogic     = new InvoiceLogic(_dbContext);
                var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                var subItemLogic     = new ItemDiscountLogic(_dbContext);
                var tableLogic       = new TableLogic(_dbContext);
                var zoneLogic        = new ZoneLogic(_dbContext);

                var listTable = await tableLogic.GetAllAsync();

                var listInvoice = await invoiceLogic.GetAllAsync(InvoiceStatus.Paid);

                var listVisualInvoice = Mapper.Map <List <VisualInvoiceModel> >(listInvoice);
                var listZone          = await zoneLogic.GetAllAsync();

                var listItem = await itemLogic.GetAllAsync();

                var listVisualItem = Mapper.Map <List <VisualItemMenuModel> >(listItem);
                var listDiscount   = await discountLogic.GetAllAsync();

                var listVisualDiscount = Mapper.Map <List <VisualItemMenuModel> >(listDiscount);

                ListItem     = new List <VisualItemMenuModel>(listVisualItem);
                ListDiscount = new List <VisualItemMenuModel>(listVisualDiscount);

                foreach (var invoice in listVisualInvoice)
                {
                    var listInvoiceItem = await invoiceItemLogic.GetAsync(invoice.Id);

                    foreach (var invoiceItem in listInvoiceItem)
                    {
                        if (invoiceItem.IsDiscount == 1)
                        {
                            var item       = ListDiscount.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            invoice.ListDiscount.Add(visualItem);
                        }
                        else
                        {
                            var item        = ListItem.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var listSubItem = await subItemLogic.GetAsync(item.Id);

                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            visualItem.ListSubItem.Add(new VisualItemMenuModel
                            {
                                Name  = "Đơn giá",
                                Value = item.Value,
                            });

                            foreach (var subItem in listSubItem)
                            {
                                var visualSubItem = ListDiscount.FirstOrDefault(h => h.Id == subItem.FkDiscount);
                                visualItem.ListSubItem.Add(new VisualItemMenuModel
                                {
                                    Id     = visualSubItem.Id,
                                    Name   = visualSubItem.Name,
                                    Value  = subItem.Value,
                                    Status = Status.Normal,
                                });
                            }

                            invoice.ListItemInBill.Add(visualItem);
                            invoice.ItemCount     += invoiceItem.Quantity;
                            invoice.OriginalPrice += invoiceItem.Value;
                        }
                        if (invoice.IsTakeAway == 0)
                        {
                            var table = listTable.First(h => h.Id == invoice.FkTable);
                            var zone  = listZone.First(h => h.Id == table.FkZone);
                            invoice.TableName = $"{zone.ZoneName} - {table.TableName}";
                        }
                        else
                        {
                            invoice.TableName = $"MANG ĐI";
                        }
                    }
                }
                ListInvoiceBindProp = new ObservableCollection <VisualInvoiceModel>(listVisualInvoice);
            }
            catch (Exception ex)
            {
                await ShowError(ex);
            }
        }
        private async void OnSave(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var discountLogic = new DiscountLogic(_dbContext);
                if (IsEditing)
                {
                    if (IsMoneyCheckedBindProp)
                    {
                        await discountLogic.UpdateAsync(new Discount
                        {
                            Id            = DiscountBindProp.Id,
                            DiscountName  = DiscountBindProp.Name,
                            DiscountValue = NormalDiscountValueBindProp,
                            IsInPercent   = 0,
                            MaxValue      = 0,
                        });

                        DiscountBindProp.Value       = NormalDiscountValueBindProp;
                        DiscountBindProp.IsInPercent = false;
                    }
                    else
                    {
                        await discountLogic.UpdateAsync(new Discount
                        {
                            Id            = DiscountBindProp.Id,
                            DiscountName  = DiscountBindProp.Name,
                            DiscountValue = NormalDiscountPercentBindProp,
                            IsInPercent   = 1,
                            MaxValue      = DiscountBindProp.MaxValue,
                        });

                        DiscountBindProp.Value       = NormalDiscountPercentBindProp;
                        DiscountBindProp.IsInPercent = true;
                    }

                    await NavigationService.GoBackAsync();
                }
                else
                {
                    if (IsMoneyCheckedBindProp)
                    {
                        await discountLogic.CreateAsync(new Discount
                        {
                            Id            = DiscountBindProp.Id,
                            DiscountName  = DiscountBindProp.Name,
                            DiscountValue = NormalDiscountValueBindProp,
                            IsInPercent   = 0,
                            MaxValue      = 0,
                        });

                        DiscountBindProp.Value       = NormalDiscountValueBindProp;
                        DiscountBindProp.IsInPercent = false;
                    }
                    else
                    {
                        await discountLogic.CreateAsync(new Discount
                        {
                            Id            = DiscountBindProp.Id,
                            DiscountName  = DiscountBindProp.Name,
                            DiscountValue = NormalDiscountPercentBindProp,
                            IsInPercent   = 1,
                            MaxValue      = DiscountBindProp.MaxValue,
                        });

                        DiscountBindProp.Value       = NormalDiscountPercentBindProp;
                        DiscountBindProp.IsInPercent = true;
                    }

                    var param = new NavigationParameters();
                    param.Add(Keys.DISCOUNT, DiscountBindProp);

                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }