Example #1
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, TransportContext transportContext)
        {
            var taskSource = new TaskCompletionSource <object>();

            try
            {
                var person = (Person)value;

                var doc = PdfGenerator.CreatePdf(person.Name);
                var ms  = new MemoryStream();

                doc.Save(ms, false);

                var bytes = ms.ToArray();
                writeStream.Write(bytes, 0, bytes.Length);
                taskSource.SetResult(null);
            }
            catch (Exception e)
            {
                taskSource.SetException(e);
            }
            return(taskSource.Task);
        }
        public ActionResult CreateQuoteWithSave(LVGquote lvgquote, string nameOfSubmit)
        {
            if (nameOfSubmit == "Save and Create Pdf")
            {
                {
                    Type = (from b in db.section1Model
                            where b.id == lvgquote.Section1ModelId
                            select b.ProjectType).SingleOrDefault();
                    Branch = (from b in db.section1Model
                            where b.id == lvgquote.Section1ModelId
                            select b.Branch).SingleOrDefault();

                    ViewBag.LiftTypes = GetLiftType1(lvgquote.CodeComplence, lvgquote.id);
                    ViewBag.LiftModels = GetLiftModel1(lvgquote.LiftType, lvgquote.EntranceType);

                    ViewBag.CarWallsLHSS = car.getCarWalls();
                    // ViewBag.CarWallsRHS = car.getCarWalls();
                    //ViewBag.CarWallsRear = car.getCarWalls();
                    ViewBag.powers = Getpower1(lvgquote.LiftType, "fake");
                    ViewBag.CodeComp = car.getobj(Type);
                    ViewBag.Phone = car.getPhone(Type);
                    ViewBag.Ceilings = car.getCeiling();
                    ViewBag.Floors = car.getFloors();
                    ViewBag.Profiles = car.getProfiles();
                    ViewBag.COP = car.getCOP();
                    ViewBag.HandrailTypes = car.getHandRailType(Type);
                    ViewBag.LDFDoorType = car.LDFDoorType(lvgquote.LiftType); ViewBag.LDFDoorFinishs1 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType1.Substring(0, 1));
                    ViewBag.LDFDoorFinishs2 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType2.Substring(0, 1));
                    ViewBag.LDFDoorFinishs3 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType3.Substring(0, 1));
                    ViewBag.LDFDoorFinishs4 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType4.Substring(0, 1));
                    ViewBag.LDFDoorFinishs5 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType5.Substring(0, 1));
                    ViewBag.LDFDoorFinishs6 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType6.Substring(0, 1));
                    ViewBag.LDFDoorFinishs7 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType7.Substring(0, 1));
                    ViewBag.LDFDoorFinishs8 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType8.Substring(0, 1));
                    ViewBag.LDFDoorFinishs9 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType9.Substring(0, 1));
                    ViewBag.LDFDoorFinishs10 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType10.Substring(0, 1));
                    ViewBag.StructureFinish = car.getStructureFinish(lvgquote.StructureType);
                    ViewBag.Claddings = car.getCladding(lvgquote.StructureType);
                    ViewBag.entrancetypes = car.getEntranceTypes(lvgquote.EntranceType);

                    // if (lVGquote.TotalSellingPrice == 0)
                    //   ModelState.AddModelError("Name", "Name is required.");

                    try
                    {
                        var actualValue = Convert.ToDecimal(lvgquote.TotalSellingPrice,
                            CultureInfo.CurrentCulture);
                    }
                    catch (FormatException e)
                    {
                        //ModelState.Errors.Add(e);
                        ModelState.AddModelError(e.Message, "Name is required.");
                    }

                    if (ModelState.IsValid)
                    {
                        lvgquote.MyType = "LVGquote";
                        db.Entry(lvgquote).State = EntityState.Modified;
                        db.SaveChanges();
                        //                   return View(lvgquote);
                    }
                }

                if (lvgquote.id == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                MainQuote lVGquote = db.MainQuote.Find(lvgquote.id);
                if (lVGquote == null)
                {
                    return HttpNotFound();

                }
                PdfDocument paragraph1 = new PdfDocument();

                string QuoteRoot = System.Configuration.ConfigurationManager.AppSettings["QuoteRoot"];
                string filename = "C:\\" + QuoteRoot + "\\" + Branch+"\\" + lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
                PdfGenerator pdfg = new PdfGenerator();
                paragraph1 = pdfg.CreatePdf(lVGquote);
                paragraph1.Save(filename);
                //// ...and start a viewer
                //   Process.Start(filename);
                var email = new NewCommentEmail
                {
                    To = "*****@*****.**",
                    UserName = lVGquote.id.ToString(),
                    //Comment = "Hello,There is a new comment from " + UserName;
                };
                // email.Attach(new Attachment(filename));
                // email.Send();
                var filesavename = lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
                return File(filename, "Application/pdf", filesavename);
            }
            else
            {

                {
                    Type = (from b in db.section1Model
                            where b.id == lvgquote.Section1ModelId
                            select b.ProjectType).SingleOrDefault();

                    ViewBag.LiftTypes = GetLiftType1(lvgquote.CodeComplence, lvgquote.id);
                    ViewBag.LiftModels = GetLiftModel1(lvgquote.LiftType, lvgquote.EntranceType);

                    ViewBag.CarWallsLHSS = car.getCarWalls();
                    // ViewBag.CarWallsRHS = car.getCarWalls();
                    //ViewBag.CarWallsRear = car.getCarWalls();
                    ViewBag.powers = Getpower1(lvgquote.LiftType, "fake");
                    ViewBag.CodeComp = car.getobj(Type);
                    ViewBag.Phone = car.getPhone(Type);
                    ViewBag.Ceilings = car.getCeiling();
                    ViewBag.Floors = car.getFloors();
                    ViewBag.Profiles = car.getProfiles();
                    ViewBag.COP = car.getCOP();
                    ViewBag.HandrailTypes = car.getHandRailType(Type);
                    ViewBag.LDFDoorType = car.LDFDoorType(lvgquote.LiftType); ViewBag.LDFDoorFinishs1 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType1.Substring(0, 1));
                    ViewBag.LDFDoorFinishs2 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType2.Substring(0, 1));
                    ViewBag.LDFDoorFinishs3 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType3.Substring(0, 1));
                    ViewBag.LDFDoorFinishs4 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType4.Substring(0, 1));
                    ViewBag.LDFDoorFinishs5 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType5.Substring(0, 1));
                    ViewBag.LDFDoorFinishs6 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType6.Substring(0, 1));
                    ViewBag.LDFDoorFinishs7 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType7.Substring(0, 1));
                    ViewBag.LDFDoorFinishs8 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType8.Substring(0, 1));
                    ViewBag.LDFDoorFinishs9 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType9.Substring(0, 1));
                    ViewBag.LDFDoorFinishs10 = car.LDFDoorFinish(lvgquote.LiftType, lvgquote.LDFDoorType10.Substring(0, 1));
                    ViewBag.StructureFinish = car.getStructureFinish(lvgquote.StructureType);
                    ViewBag.Claddings = car.getCladding(lvgquote.StructureType);
                    ViewBag.entrancetypes = car.getEntranceTypes(lvgquote.EntranceType);

                    // if (lVGquote.TotalSellingPrice == 0)
                    //   ModelState.AddModelError("Name", "Name is required.");

                    try
                    {
                        var actualValue = Convert.ToDecimal(lvgquote.TotalSellingPrice,
                            CultureInfo.CurrentCulture);
                    }
                    catch (FormatException e)
                    {
                        //ModelState.Errors.Add(e);
                        ModelState.AddModelError(e.Message, "Name is required.");
                    }

                    if (ModelState.IsValid)
                    {
                        lvgquote.MyType = "LVGquote";
                        db.Entry(lvgquote).State = EntityState.Modified;
                        db.SaveChanges();
                        //return View(lvgquote);
                    }
                    return RedirectToAction("Edit", "LVGquotes", new { id = lvgquote.id });
                }

            }
        }
        public ActionResult SendEmail(int id)
        {
            MainQuote lVGquote = db.MainQuote.Find(id);
            Branch = (from b in db.section1Model
                            where b.id == lVGquote.Section1ModelId
                            select b.Branch).SingleOrDefault();
            PdfDocument paragraph1 = new PdfDocument();
            string QuoteRoot = System.Configuration.ConfigurationManager.AppSettings["QuoteRoot"];
            string filename = "C:\\" + QuoteRoot + "\\" + Branch + "\\" + lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
            PdfGenerator pdfg = new PdfGenerator();
            paragraph1 = pdfg.CreatePdf(lVGquote);
            paragraph1.Save(filename);

            ViewBag.id = id;
            ViewBag.filename = filename;
            var filesavename = lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
            ViewBag.filenamename = filesavename;
            // File(filename, "Application/pdf", filesavename);
            return View(new Models.MailModel(id));
        }
        //create quote
        public ActionResult CreateQuote(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            MainQuote lVGquote = db.MainQuote.Find(id);
            if (lVGquote == null)
            {
                return HttpNotFound();

            }

            Branch = (from b in db.section1Model
                      where b.id == lVGquote.Section1ModelId
                      select b.Branch).SingleOrDefault();
            PdfDocument paragraph1 = new PdfDocument();
            string QuoteRoot = System.Configuration.ConfigurationManager.AppSettings["QuoteRoot"];
              //  string filename = "\\\\elhe-syd-ad1\\" + QuoteRoot + "\\" + Branch + "\\Quote" + lVGquote.id + ".pdf";
            string filename = "C:\\" + QuoteRoot + "\\" + Branch + "\\" + lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
            PdfGenerator pdfg = new PdfGenerator();
            paragraph1 = pdfg.CreatePdf(lVGquote);
            paragraph1.Save(filename);
            //// ...and start a viewer
            //   Process.Start(filename);
            var email = new NewCommentEmail
            {
                To = "*****@*****.**",
                UserName = lVGquote.id.ToString(),
                //Comment = "Hello,There is a new comment from " + UserName;
            };
            // email.Attach(new Attachment(filename));
            // email.Send();
            var filesavename = lVGquote.LiftType + "_P" + lVGquote.Section1ModelId + "-" + lVGquote.id + ".pdf";
            return File(filename, "Application/pdf", filesavename);
        }