/// <summary> /// Manage the creation of the invoice /// /// </summary> /// <returns></returns> private int InvoiceCreation() { int result = 0; try { if (this.Session["CustID"] != null && this.Session["Email"] != null) { //Email and Cart Recuperation from session string email = this.Session["Email"].ToString(); List <ProductSelectionDTO> cart = (List <ProductSelectionDTO>)(this.Session["Cart"]); //Postage Id recuperation from Cell[0] of selected Row int postageID = Convert.ToInt32(PostagesTable.Rows[PostagesTable.SelectedIndex].Cells[0].Text); //Invoice costs recuperation from labels decimal postage = Convert.ToDecimal(lblPostageValue.Text); decimal amount = Convert.ToDecimal(lblAmountValue.Text); int tax = Convert.ToInt16(lblTaxValue.Text); decimal cost = Convert.ToDecimal(TotalCostValue.Text); //Invoice creation result = blInvoice.CreateInvoice(email, postageID, cart, postage, amount, tax, cost); //Update the stock in DB if (result > 0) { //Give invoiceID, cart and way to update (reverse or not) / if equal to 0, there is an error during the update if (blInvoice.UpdateStockProductSelection(result, cart, false) == 0) { lblValidation.Text = "Error DataBase"; } else { //If the update is correctly executed, invoiceID is set as variable session and used to authenticate on the Payment page this.Session["InvoiceID"] = result; } } } else { lblValidation.Text = "Error in authentication, please Login again."; } } catch (Exception ex) { ex.GetBaseException(); Debug.Write(ex.ToString()); lblValidation.Text = "Error during invoice creation."; } return(result); }
public AjaxResult SaveNewInvoice(InvoiceViewModel invoiceViewModel) { var ajaxResult = new AjaxResult(); try { using (InvoiceBL invoiceBL = new InvoiceBL()) { var invoice = invoiceBL.MapInvoiceViewModelToInvoice(invoiceViewModel); invoiceBL.CreateInvoice(invoice); ajaxResult.Data = invoice.InvoiceID; ajaxResult.Success = true; } } catch (Exception) { ajaxResult.Success = false; ajaxResult.Messenger = "Có lỗi xảy ra khi lưu hóa đơn lên server. Vui lòng liên hệ MISA!"; } return(ajaxResult); }