private Balustrade CreateBalustradeFromDrawingModel(BalustradeDrawingModel model)
        {
            var balustrade = new Balustrade
            {
                Color            = DbSession.Get <ColorLocal>(model.ColorId),
                GlassSystem      = DbSession.Get <GlassSystemLocal>(model.GlassId),
                BalustradeSystem = DbSession.Get <BalustradeSystemLocal>(model.SystemId)
            };

            balustrade.UpdateSystemDefaults();
            InitializeViews(balustrade);


            balustrade.StartType = model.StartType;
            balustrade.EndType   = model.EndType;

            balustrade.AluminumSpacers = true;

            if (model.HRBR.HasValue && model.HRBR.Value > 0)
            {
                balustrade.HRBR  = model.HRBR.Value;
                balustrade.HRBRC = true;
            }

            if (model.BRHR.HasValue && model.BRHR.Value > 0)
            {
                balustrade.BRHR  = model.BRHR.Value;
                balustrade.BRHRC = true;
            }

            balustrade.DrawBlack        = false;
            balustrade.CurrentViewIndex = model.ViewIndex % balustrade.BalustradeViews.Count;

            if (model.StartWallAngle.HasValue)
            {
                balustrade.WSA  = model.StartWallAngle.Value;
                balustrade.WSAR = false;
            }

            if (model.EndWallAngle.HasValue)
            {
                balustrade.WEA  = model.EndWallAngle.Value;
                balustrade.WEAR = false;
            }

            var i = 0;

            foreach (var section in model.Sections)
            {
                var balSection = new BalustradeSection
                {
                    Balustrade              = balustrade,
                    Length                  = section.Length,
                    Angle                   = section.Angle,
                    Ofst                    = section.Ofst ?? 0,
                    CalculatePostsQuantity  = true,
                    CalculateHandrailJoints = true,
                    PreferStockGlass        = balustrade.BalustradeSystem.PreferStockGlass
                };

                if (i == 0 && model.WG.HasValue)
                {
                    balSection.PreferStockGlass = false;
                    balustrade.WG = model.WG.Value;
                }

                if (i == model.Sections.Count - 1 && model.GW.HasValue)
                {
                    balSection.PreferStockGlass = false;
                    balustrade.GW = model.GW.Value;
                }

                balustrade.RawBalustradeSections.Add(balSection);
                i += 1;
            }

            return(balustrade);
        }
        public ActionResult Quote(BalustradeQuoteModel model)
        {
            if (!model.ModelId.HasValue)
            {
                return(RedirectToAction("quote"));
            }

            var balustrade = new Balustrade();

            balustrade.Color            = DbSession.Get <ColorLocal>(model.ColorId);
            balustrade.GlassSystem      = DbSession.Get <GlassSystemLocal>(model.GlassId);
            balustrade.BalustradeSystem = DbSession.Get <BalustradeSystemLocal>(model.TypeId);
            balustrade.UpdateSystemDefaults();
            balustrade.StartType = BalustradeSection.SectionFinishType.Wall;
            balustrade.EndType   = BalustradeSection.SectionFinishType.Wall;
            balustrade.ModelId   = model.ModelId;

            var angle = model.Dims.Count > 1 ? 90D : 0D;

            foreach (var dimension in model.Dims)
            {
                var section = new BalustradeSection
                {
                    Balustrade              = balustrade,
                    Angle                   = angle,
                    Length                  = dimension.Length ?? 0,
                    Depth                   = dimension.Curved ? 10 : 0,
                    CalculatePostsQuantity  = true,
                    CalculateHandrailJoints = true,
                    PreferStockGlass        = balustrade.BalustradeSystem.PreferStockGlass
                };
                balustrade.RawBalustradeSections.Add(section);
                angle -= 90;
            }

            var modelFromDb = DbSession.Get <BalustradeModel>(model.ModelId.Value);

            Session[SessionKeys.LAST_QUOTE] = new BalustradeQuoteModel(modelFromDb, balustrade, model.P);

            if (model.Action == BalustradeQuoteModel.AddToCartText)
            {
                DbSession.SaveOrUpdate(balustrade);

                AddToCart(balustrade, 1);
                DbSession.Flush();

                return(RedirectToAction("cart", "customer", new { areas = AreaKind }));
            }

            var line = new QuoteLine();

            line.Name        = balustrade.Name;
            line.Price       = balustrade.SilverSellingPrice;
            line.BronzePrice = balustrade.BronzeSellingPrice;
            line.GoldPrice   = balustrade.GoldSellingPrice;

            line.ProductDetails = balustrade;
            Session[SessionKeys.PENDING_QUOTE_LINE] = line;


            return(RedirectToAction("create-quote", "customer", new { areas = AreaKind }));
        }