Exemplo n.º 1
0
        public async Task <IActionResult> UpdateInvoice(InvoiceForCreateDto invoiceDto)
        {
            var ok = await _mediator.Send(new UpdateInvoiceCommand(invoiceDto));

            if (ok)
            {
                return(NoContent());
            }
            else
            {
                return(BadRequest("Không thể cập nhật hóa đơn!"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateInvoice(InvoiceForCreateDto invoiceDto)
        {
            var invoice = await _mediator.Send(new AddInvoiceCommand(invoiceDto));

            if (invoice != null)
            {
                return(CreatedAtRoute(nameof(GetInvoice), new { id = invoice.Id }, invoice));
            }
            else
            {
                return(BadRequest("Không thể tạo mới!"));
            }
        }
 public UpdateInvoiceCommand(InvoiceForCreateDto invoice)
 {
     Invoice = invoice;
 }
Exemplo n.º 4
0
 public AddInvoiceCommand(InvoiceForCreateDto invoice)
 {
     Invoice = invoice;
 }
Exemplo n.º 5
0
        private async void OnSaveInvoice(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!Application.Current.Properties.ContainsKey("session"))
                {
                    await PageDialogService.DisplayAlertAsync("Thông báo", "Chưa bắt đầu phiên làm việc!", "Đồng ý");

                    await NavigationService.NavigateAsync(nameof(SessionPage));

                    return;
                }
                if (InvoiceBindProp.Table == null)
                {
                    await PageDialogService.DisplayAlertAsync("Thông báo", "Chưa chọn bàn!", "Đồng ý");

                    var selectedCategory = ListCategoryBindProp.FirstOrDefault(z => z.IsSelected);
                    if (selectedCategory != null)
                    {
                        selectedCategory.IsSelected = false;
                    }
                    MenuFrameVisibleBindProp        = false;
                    InvoiceFrameVisibleBindProp     = true;
                    ListInvoiceFrameVisibleBindProp = false;
                    ZoneFrameVisibleBindProp        = true;
                }
                else
                {
                    var invoiceToCreate = new InvoiceForCreateDto(InvoiceBindProp);
                    var json            = JsonConvert.SerializeObject(invoiceToCreate);
                    var content         = new StringContent(json, Encoding.UTF8, "application/json");
                    // Thuc hien cong viec tai day
                    using (var client = new HttpClient())
                    {
                        HttpResponseMessage response = new HttpResponseMessage();
                        if (InvoiceBindProp.Id == Guid.Empty)
                        {
                            response = await client.PostAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        else
                        {
                            response = await client.PutAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        switch (response.StatusCode)
                        {
                        case HttpStatusCode.Created:
                            var invoice = JsonConvert.DeserializeObject <InvoiceDto>(await response.Content.ReadAsStringAsync());
                            await _connection.InvokeAsync("SendInvoice", invoice);

                            CurrentZone.IsSelected          = false;
                            CurrentCategory.IsSelected      = false;
                            InvoiceBindProp                 = null;
                            MenuFrameVisibleBindProp        = false;
                            ListInvoiceFrameVisibleBindProp = true;
                            ZoneFrameVisibleBindProp        = false;
                            InvoiceFrameVisibleBindProp     = true;
                            SettingFrameVisibleBindProp     = false;
                            DiscountFrameVisibleBindProp    = false;
                            break;

                        case HttpStatusCode.NoContent:
                            await _connection.InvokeAsync("UpdateInvoice", InvoiceBindProp);

                            TempInvoiceBindProp             = InvoiceBindProp;
                            TempInvoiceBindProp             = null;
                            InvoiceBindProp                 = null;
                            CurrentCategory.IsSelected      = false;
                            CurrentZone.IsSelected          = false;
                            MenuFrameVisibleBindProp        = false;
                            ListInvoiceFrameVisibleBindProp = true;
                            ZoneFrameVisibleBindProp        = false;
                            MenuFrameVisibleBindProp        = false;
                            InvoiceFrameVisibleBindProp     = true;
                            SettingFrameVisibleBindProp     = false;
                            DiscountFrameVisibleBindProp    = false;
                            break;
                        }
                    };
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private async void OnCompeletePayment(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            if (ReceivedMoneyBindProp < InvoiceBindProp.TotalPrice)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!IsCompletedBindProp)
                {
                    IsCompletedBindProp = true;
                }
                else
                {
                    var invoiceToCreate = new InvoiceForCreateDto(InvoiceBindProp);
                    invoiceToCreate.Tip        = TipBindProp;
                    invoiceToCreate.IsPaid     = true;
                    invoiceToCreate.ClosedAt   = DateTime.Now;
                    invoiceToCreate.PaidAmount = ReceivedMoneyBindProp;
                    var json    = JsonConvert.SerializeObject(invoiceToCreate);
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    // Thuc hien cong viec tai day
                    using (var client = new HttpClient())
                    {
                        HttpResponseMessage response = new HttpResponseMessage();
                        if (InvoiceBindProp.Id == Guid.Empty)
                        {
                            response = await client.PostAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        else
                        {
                            response = await client.PutAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        if (response.IsSuccessStatusCode)
                        {
                            var session = Application.Current.Properties["session"] as SessionDto;
                            session.Revenue       += InvoiceBindProp.TotalPrice;
                            session.Tip           += TipBindProp;
                            session.ExpectedMoney += InvoiceBindProp.TotalPrice + TipBindProp;

                            var param = new NavigationParameters();
                            param.Add(nameof(InvoiceBindProp), InvoiceBindProp);
                            await NavigationService.GoBackAsync(param);
                        }
                    };
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }