public LogicResult Save(ProductInvoiceModel model) { try { var dto = new UserToProductDTO { Amount = model.PaymentDetail.TotalPrice, UserId = CurrentUser.Id, PaymentDetail = SerializerHelper.Serialize(model.PaymentDetail), Day = model.Day, ProductId = model.Id, Point = model.Point, }; var result = _userToProductService.Save(dto); if (result.IsSucceed) { var product = Store.CartProducts.FirstOrDefault(m => m.Id == model.Id); Store.CartProducts.Remove(product); return(LogicResult.Succeed()); } else { return(LogicResult.Failure(Validation.UnSuccessfullOperation)); } } catch { return(LogicResult <int> .Failure(Validation.UnSuccessfullOperation)); } }
public LogicResult <MemoryStream> GenerateInvoicePdf(ProductInvoiceModel invoice) { try { MemoryStream workStream = new MemoryStream(); Document doc = new Document(); doc.SetMargins(0f, 0f, 0f, 0f); //Create PDF Table with 5 columns PdfPTable tableLayout = new PdfPTable(8); doc.SetMargins(0f, 0f, 0f, 0f); //Create PDF Table PdfWriter.GetInstance(doc, workStream).CloseStream = false; doc.Open(); //Add Content to PDF doc.Add(AddContentToPDF(tableLayout, invoice)); // Closing the document doc.Close(); byte[] byteInfo = workStream.ToArray(); workStream.Write(byteInfo, 0, byteInfo.Length); workStream.Position = 0; return(LogicResult <MemoryStream> .Succeed(workStream)); } catch { return(LogicResult <MemoryStream> .Failure(Validation.UnSuccessfullOperation)); } }
public ActionResult Save(ProductInvoiceModel model) { var result = _cartServiceFacade.Save(model); if (result.IsSucceed) { return(Json(new { IsSucceed = result.IsSucceed }, JsonRequestBehavior.AllowGet)); } else { return(AjaxFailureResult(result)); } }
protected PdfPTable AddContentToPDF(PdfPTable tableLayout, ProductInvoiceModel invoice) { float[] headers = { 40, 30, 20, 20, 20, 20, 20, 20 }; //Header Widths tableLayout.SetWidths(headers); //Set the pdf headers tableLayout.WidthPercentage = 100; //Set the PDF File witdh percentage tableLayout.HeaderRows = 1; //Add Title to the PDF file at the top tableLayout.AddCell(new PdfPCell(new Phrase(UI.Resources.UI.Invoice, new Font(Font.FontFamily.HELVETICA, 8, 1, new iTextSharp.text.BaseColor(0, 0, 0)))) { Colspan = 12, Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_CENTER }); ////Add header AddCellToHeader(tableLayout, UI.Resources.UI.ProductName); AddCellToHeader(tableLayout, Resources.UI.ProductType); AddCellToHeader(tableLayout, Resources.UI.DayQuantity); AddCellToHeader(tableLayout, Resources.UI.OneTime); AddCellToHeader(tableLayout, Resources.UI.Premium); AddCellToHeader(tableLayout, Resources.UI.Regular); AddCellToHeader(tableLayout, Resources.UI.TotalPrice); AddCellToHeader(tableLayout, Resources.UI.EarnedPoint); ////Add body AddCellToBody(tableLayout, invoice.Name); AddCellToBody(tableLayout, invoice.Type); AddCellToBody(tableLayout, invoice.Day.ToString()); AddCellToBody(tableLayout, invoice.PaymentDetail.OneTime.ToString() + " €"); AddCellToBody(tableLayout, invoice.PaymentDetail.Premium.ToString() + " €"); AddCellToBody(tableLayout, invoice.PaymentDetail.Regular.ToString() + " €"); AddCellToBody(tableLayout, invoice.PaymentDetail.TotalPrice.ToString() + " €"); AddCellToBody(tableLayout, invoice.Point.ToString()); return(tableLayout); }