public void SendEmail(string email, int id) { MailManager mm = new MailManager(); CreatePDF(id); CATERING catering = db.CATERINGs.Where(x => x.ID_CATERING == id).FirstOrDefault(); var body = "Please find attached the catering information."; SmtpClient smtpCliente = new SmtpClient(); smtpCliente.Host = "relay-hosting.secureserver.net "; smtpCliente.Port = 25; smtpCliente.EnableSsl = false; smtpCliente.UseDefaultCredentials = true; smtpCliente.Credentials = new NetworkCredential { UserName = "******", Password = "******" }; var mailMEssage = new MailMessage(); mailMEssage.From = new MailAddress("*****@*****.**", "Catering Order"); mailMEssage.Subject = "NEW ORDER. SCHEDULED DATE: " + catering.EVENT_DATE.Value.ToShortDateString() + " from " + catering.CLIENT.NAME + " " + catering.CLIENT.SURNAME; mailMEssage.Body = body; mailMEssage.To.Add(email); try { mailMEssage.Attachments.Add(new Attachment(Server.MapPath("~/Uploads/" + catering.CLIENT.NAME + "_" + catering.CLIENT.SURNAME + ".pdf"))); } catch (Exception) { throw; } mailMEssage.IsBodyHtml = true; smtpCliente.Send(mailMEssage); }
// GET: DateTimePicker public ActionResult Index() { dishupEntities db = new dishupEntities(); CATERING c = db.CATERINGs.Where(x => x.ID_CATERING == 5).FirstOrDefault(); return(View(c)); }
public ActionResult DeleteConfirmed(int id) { CATERING cATERING = db.CATERINGs.Find(id); cATERING.deleted = 1; db.Entry(cATERING).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID_CATERING,ID_CLIENT,ID_MENU,AMOUNT_PEOPLE,ADDRESS,EVENT_DATE,EVENT_TIME,NOTES,HAS_PARKING,DELETED")] CATERING cATERING) { if (ModelState.IsValid) { cATERING.deleted = 0; db.Entry(cATERING).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID_CLIENT = new SelectList(db.CLIENTs, "ID_CLIENT", "NAME", cATERING.ID_CLIENT); ViewBag.ID_MENU = new SelectList(db.MENUs, "ID_MENU", "NOMBRE", cATERING.ID_MENU); return(View(cATERING)); }
// GET: CATERINGs/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CATERING cATERING = db.CATERINGs.Find(id); if (cATERING == null) { return(HttpNotFound()); } return(View(cATERING)); }
public void CreatePDF(int ID) { //Bring the Catering Object. CATERING cat = db.CATERINGs.Find(ID); var filePath = Server.MapPath("~/Uploads/") + cat.CLIENT.NAME + "_" + cat.CLIENT.SURNAME + ".pdf"; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } // Create a Document object var document = new Document(PageSize.A4, 50, 50, 25, 25); // Create a new PdfWrite object, writing the output to a MemoryStream var writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/Uploads/") + cat.CLIENT.NAME + "_" + cat.CLIENT.SURNAME + ".pdf", FileMode.Create)); // Open the Document for writing; document.Open(); // First, create our fonts... (For more on working w/fonts in iTextSharp, see: http://www.mikesdotnetting.com/Article/81/iTextSharp-Working-with-Fonts var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD); var subTitleFont = FontFactory.GetFont("Arial", 14, Font.BOLD); var boldTableFont = FontFactory.GetFont("Arial", 12, Font.BOLD); var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC); var bodyFont = FontFactory.GetFont("Arial", 12, Font.NORMAL); // Add the "Northwind Traders Receipt" title document.Add(new iTextSharp.text.Paragraph("Pablo's Kitchen Catering Order", titleFont)); // Now add the "Thank you for shopping at Northwind Traders. Your order details are below." message document.Add(new Paragraph("Read the information carefully and make sure to double check the order.", bodyFont)); document.Add(Chunk.NEWLINE); // Add the "Order Information" subtitle document.Add(new Paragraph("Order Information", subTitleFont)); // Create the Order Information table - see http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables for more info var orderInfoTable = new PdfPTable(2); orderInfoTable.HorizontalAlignment = 0; orderInfoTable.SpacingBefore = 20; orderInfoTable.SpacingAfter = 20; orderInfoTable.DefaultCell.Border = 0; orderInfoTable.SetWidths(new int[] { 5, 9 }); orderInfoTable.AddCell(new Phrase("Client Name:", boldTableFont)); orderInfoTable.AddCell(cat.CLIENT.NAME + " " + cat.CLIENT.SURNAME); orderInfoTable.AddCell(new Phrase("Contact Number:", boldTableFont)); orderInfoTable.AddCell(cat.CLIENT.MOBILE_NUMBER); orderInfoTable.AddCell(new Phrase("Address:", boldTableFont)); orderInfoTable.AddCell(cat.ADDRESS); orderInfoTable.AddCell(new Phrase("Delivery Date & Time:", boldTableFont)); orderInfoTable.AddCell(cat.EVENT_DATE.Value.ToShortDateString() + " " + cat.EVENT_TIME); orderInfoTable.AddCell(new Phrase("Departure Time:", boldTableFont)); orderInfoTable.AddCell(cat.DEPARTURE_TIME); orderInfoTable.AddCell(new Phrase("Arrival Time:", boldTableFont)); orderInfoTable.AddCell(cat.ARRIVAL_TIME); document.Add(orderInfoTable); // Add the "Items In Your Order" subtitle document.Add(new Paragraph("Order Description", subTitleFont)); // Create the Order Details table var orderDetailsTable = new PdfPTable(3); orderDetailsTable.HorizontalAlignment = 0; orderDetailsTable.SpacingBefore = 10; orderDetailsTable.SpacingAfter = 10; orderDetailsTable.DefaultCell.Border = 0; orderDetailsTable.AddCell(new Phrase("Supplie:", boldTableFont)); orderDetailsTable.AddCell(new Phrase("Quantity:", boldTableFont)); orderDetailsTable.AddCell(new Phrase("Packaging:", boldTableFont)); List <CAT_INS_PACK> suppliesList = db.CAT_INS_PACK.Where(x => x.ID_CATERING == ID && x.ACTIVE == 1).ToList(); StringBuilder strBuilder = new StringBuilder(); foreach (CAT_INS_PACK ci in suppliesList) { orderDetailsTable.AddCell(new Phrase(ci.INSUMO.NOMBRE)); if (ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value >= 1000) { switch (ci.INSUMO.MEDIDA.NOMBRE) { case "Gramos": var x = ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value; x = x / 1000; orderDetailsTable.AddCell(x.ToString() + " Kilo/s"); break; case "Ml": var y = ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value; y = y / 1000; orderDetailsTable.AddCell(y.ToString() + " Litre/s"); break; case "Unidad": orderDetailsTable.AddCell(ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value + " Units"); break; default: orderDetailsTable.AddCell(ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value.ToString()); break; } } else { switch (ci.INSUMO.MEDIDA.NOMBRE) { case "Gramos": var x = ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value; orderDetailsTable.AddCell(x.ToString() + " Gramos."); break; case "Ml": var y = ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value; orderDetailsTable.AddCell(y.ToString() + " Ml."); break; case "Unidad": orderDetailsTable.AddCell(ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value + " Units"); break; default: orderDetailsTable.AddCell(ci.CATERING.CATERING_INSUMO.Where(o => o.ID_INSUMO == ci.ID_INSUMO && o.ID_CATERING == ID).Select(o => o.QUANTITY).FirstOrDefault().Value + " " + ci.INSUMO.MEDIDA.NOMBRE); break; } } orderDetailsTable.AddCell(ci.QUANTITY.ToString() + " " + ci.PACKAGING.NAME); } document.Add(orderDetailsTable); // Add ending message var endingMessage = new Paragraph("Please make sure to double check the order. If you have any doubt about it, please contact your Supervisor.", endingMessageFont); endingMessage.Alignment = Element.ALIGN_CENTER; document.Add(endingMessage); // Finally, add an image in the upper right corner var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Resources/Logo-DishUp.png")); logo.ScaleAbsoluteWidth(120F); logo.ScaleAbsoluteHeight(100F); logo.SetAbsolutePosition(480, 730); document.Add(logo); document.Close(); //Response.ContentType = "application/pdf"; //Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Receipt-{0}.pdf", cat.CLIENT.NAME)); }
public ActionResult Create([Bind(Include = "ID_CATERING,ARRIVAL_TIME,DEPARTURE_TIME,ID_CLIENT,ID_MENU,AMOUNT_PEOPLE,ADDRESS,EVENT_DATE,NOTES,HAS_PARKING")] CATERING cATERING) { if (ModelState.IsValid) { List <PRODUCTO> listaProductos = db.MENU_PRODUCTO.Where(x => x.ID_MENU == cATERING.ID_MENU).Select(x => x.PRODUCTO).ToList(); List <INSUMO> listaInsumo = db.MENU_INSUMO.Where(x => x.ID_MENU == cATERING.ID_MENU && x.ACTIVE == 1).Select(x => x.INSUMO).ToList(); List <CAT_INS_PACK> packagingCatering = new List <CAT_INS_PACK>(); Dictionary <string, int?> listaInsumos = new Dictionary <string, int?>(); var cantPersonas = cATERING.AMOUNT_PEOPLE; cATERING.deleted = 0; StringBuilder errorPackaging = new StringBuilder(); db.CATERINGs.Add(cATERING); for (int i = 0; i < cantPersonas; i++) { Dictionary <string, int?> listaInsu = new Dictionary <string, int?>(); listaInsu = db.MENU_INSUMO.Where(x => x.ID_MENU == cATERING.ID_MENU && x.ACTIVE == 1).Select(x => new { x.INSUMO.NOMBRE, x.QUANTITY }).ToDictionary(t => t.NOMBRE, t => t.QUANTITY); foreach (KeyValuePair <string, int?> list in listaInsu) { if (!listaInsumos.ContainsKey(list.Key)) { listaInsumos.Add(list.Key, list.Value); } else { var valorInsumo = listaInsumos.Where(x => x.Key == list.Key).Select(x => x.Value).First(); valorInsumo = valorInsumo + list.Value; listaInsumos[list.Key] = valorInsumo; } } } //GENERO LISTA PARA INSERTAR LOS INSUMOS. var l = listaInsumos; var s = (from l_insumo in listaInsumos join ins in db.INSUMOes on l_insumo.Key equals ins.NOMBRE join med in db.MEDIDAs on ins.ID_MEDIDA equals med.ID_MEDIDA select new InsumosViewModel { id = ins.ID_INSUMO, nombreInsumo = l_insumo.Key, nombre = med.NOMBRE, quantity = l_insumo.Value }).ToList(); foreach (InsumosViewModel it in s) { INSUMO_PACKAGING ip = db.INSUMO_PACKAGING.Where(x => x.ID_INSUMO == it.id && cantPersonas <= x.maxPerson && cantPersonas >= x.minPerson).OrderBy(x => x.QUANTITY).FirstOrDefault(); try { var cantPackaging = it.quantity / ip.QUANTITY; if (cantPackaging == 0) { cantPackaging = 1; } db.CAT_INS_PACK.Add(new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, QUANTITY = cantPackaging, ID_INSUMO = it.id, ID_PACKAGING = ip.ID_PACKAGING, ACTIVE = 1 }); } catch (Exception ex) { errorPackaging.AppendLine("Id Insumo:" + it.id + " ex: " + ex.InnerException); db.INSUMO_PACKAGING_PENDING.Add(new INSUMO_PACKAGING_PENDING { ACTIVE = true, ID_INSUMO = it.id, QUANTITY = it.quantity, }); } if (it.id == 39) { double quant = Convert.ToDouble(it.quantity / 2); db.CATERING_INSUMO.Add(new CATERING_INSUMO { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = Convert.ToInt16(it.id), QUANTITY = quant, ACTIVE = 1 }); } else { db.CATERING_INSUMO.Add(new CATERING_INSUMO { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = Convert.ToInt16(it.id), QUANTITY = it.quantity, ACTIVE = 1 }); } } //AGREGO INSUMOS EXTRA POR MENU. //switch (cATERING.ID_MENU) //{ // case 1: // break; // case 2: // CATERING_INSUMO CAT = new CATERING_INSUMO // { // ID_INSUMO = 66, // QUANTITY = 500, // ID_CATERING = cATERING.ID_CATERING // }; // db.CATERING_INSUMO.Add(CAT); // break; //} //PREPARO PACKAGING. foreach (InsumosViewModel ins in s) { } switch (cATERING.ID_MENU) { case 1: break; case 2: double cateringBox = Convert.ToDouble(cantPersonas) / 10; cateringBox = Math.Round(cateringBox); //Extra Corn Chips. CAT_INS_PACK cornChips = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 64, QUANTITY = 1, ID_PACKAGING = 8 }; //Hot Sauce. CAT_INS_PACK hotSauce = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 23, QUANTITY = 1, ID_PACKAGING = 5 }; //Extra Guacamole CAT_INS_PACK exTraGuacamole = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 66, QUANTITY = 1, ID_PACKAGING = 4 }; //CATERING BOX CAT_INS_PACK catBox = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 66, QUANTITY = Convert.ToInt16(cateringBox), ID_PACKAGING = 8 }; db.CAT_INS_PACK.Add(cornChips); db.CAT_INS_PACK.Add(hotSauce); db.CAT_INS_PACK.Add(exTraGuacamole); db.CAT_INS_PACK.Add(catBox); break; case 3: double cornChipsCant = Convert.ToDouble(cantPersonas) / 15; cornChipsCant = Math.Round(cornChipsCant); //Extra Corn Chips. CAT_INS_PACK cornChips2 = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 64, QUANTITY = Convert.ToInt16(cornChipsCant), ID_PACKAGING = 8 }; //BlackBowl CAT_INS_PACK blackBowl = new CAT_INS_PACK { ID_CATERING = cATERING.ID_CATERING, ID_INSUMO = 67, QUANTITY = cantPersonas, ID_PACKAGING = 4 }; db.CAT_INS_PACK.Add(cornChips2); db.CAT_INS_PACK.Add(blackBowl); break; case 4: break; case 5: break; case 6: break; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID_CLIENT = new SelectList(db.CLIENTs, "ID_CLIENT", "NAME", cATERING.ID_CLIENT); ViewBag.ID_MENU = new SelectList(db.MENUs, "ID_MENU", "NOMBRE", cATERING.ID_MENU); return(View(cATERING)); }