public ActionResult Edit(LVGquote lVGquote)
        {
            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.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);

            try
            {
                var actualValue = Convert.ToDecimal(lVGquote.TotalSellingPrice,
                    CultureInfo.CurrentCulture);
            }
            catch (FormatException 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 View(lVGquote);
        }
        public ActionResult Create(LVGquote lVGquote)
        {
            if (ModelState.IsValid)
            {
                lVGquote.MyType = "LVGquote";
                db.MainQuote.Add(lVGquote);
                db.SaveChanges();

                var model =
               (from r in db.section1Model
                where r.id == lVGquote.Section1ModelId
                select r).SingleOrDefaultAsync();
                // return View(model);

                return RedirectToAction("Edit", "LVGquotes", new { id = lVGquote.id });
            }

            ViewBag.ProductId = lVGquote.Section1ModelId;
            ViewBag.CodeComp = car.getobj(Type);
            ViewBag.LiftTypes = GetLiftType1(lVGquote.CodeComplence, lVGquote.id);
            ViewBag.LiftModels = GetLiftModel1(lVGquote.LiftType, lVGquote.EntranceType);

            ViewBag.CarWallsLHSS = car.getCeiling();

            ViewBag.powers = Getpower1(lVGquote.LiftType, "fake");
            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);

            return View(lVGquote);
        }
        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 = "[email protected]",
                    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 });
                }

            }
        }
        // GET: LVGquotes/Create
        public ActionResult Create(int section_1)
        {
            Type = (from b in db.section1Model
                    where b.id == section_1
                    select b.ProjectType).SingleOrDefault();

            ViewBag.SectionType = Type;
            ViewBag.ProductId = section_1;

            LVGquote model = new LVGquote();

            var lifttypes = car.getLiftTypes(Type);
            var lift = GetLift(lifttypes, 0);
            ViewBag.LiftTypes = GetLiftType1(lifttypes, 0);
            ViewBag.LiftModels = GetLiftModel1(lift, "Front entrance");

            if (lift == "DomusLift")
            {
                model.IntCarSizeDeep = "1300";
                model.IntCarSizeWide = "1000";
                model.ShaftSizeDeep = "1450";
                model.ShaftSizeWide = "1400";
                model.Door1SizeWide = "950";
                model.Doo1SizeDeep = "2000";
                model.Headroom = 2450;
                model.Pit = 130;
                model.Travel = 3000;
                model.CarHeight = 2000;
                model.ConCabSize = "600mm W x  280mm D x 1000mm H";
                model.ConCabLocVer = "0";
                model.ConCabLocHor = "2500";
                model.Speed = "0.25";
            }
            else
            {
                model.IntCarSizeDeep = "1400";
                model.IntCarSizeWide = "1100";
                model.ShaftSizeDeep = "1550";
                if (lift == "Domus Evolution")
                {
                    model.ShaftSizeWide = "1550";
                }
                else {
                    model.ShaftSizeWide = "1500";
                }
                model.Door1SizeWide = "900";
                model.Doo1SizeDeep = "2000";
                model.Headroom = 2500;
                model.Pit = 130;
                model.Travel = 3000;
                model.CarHeight = 2000;
                model.ConCabSize = "720 mm W x 360 mm D x 1500 mm H";
                model.ConCabLocVer = "0";
                model.ConCabLocHor = "2500";
                model.Speed = "0.15";
            }
            ViewBag.CarWallsLHSS = car.getCarWalls();
            // ViewBag.CarWallsRHS = car.getCarWalls();
            //ViewBag.CarWallsRear = car.getCarWalls();

            ViewBag.powers = Getpower1(lift, "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(lift);
            ViewBag.LDFDoorFinish = car.LDFDoorFinish(lift, "B");
            ViewBag.StructureFinish = car.getStructureFinish("Aluminium");
            ViewBag.Claddings = car.getCladding("Aluminium");
            ViewBag.entrancetypes = car.getEntranceTypes("Front entrance");

            return View(model);
        }