private void ReloadPass(bool isNew = false)
        {
            if (isNew)
            {
                _hotelRepository   = new HotelRepository();
                _productRepository = new ProductRepository();
                _isReload          = true;
            }
            var passLimit = _hotelRepository.GetDailyPassLimit(_hotels.HotelId);

            CurrentPass.Text = passLimit.DailyPass.ToString();
            HidPass.Value    = passLimit.DailyPass.ToString();

            CurrentCabana.Text = passLimit.CabanaPass.ToString();
            HidCabana.Value    = passLimit.CabanaPass.ToString();

            CurrentSpa.Text  = passLimit.SpaPass.ToString();
            HidSpaPass.Value = passLimit.SpaPass.ToString();

            CurrentDayBed.Text = passLimit.DaybedPass.ToString();
            HidDayBed.Value    = passLimit.DaybedPass.ToString();

            var addOns = _productRepository.GetByHotelId(_hotels.HotelId, (int)Enums.ProductType.AddOns);

            RptAddOns.DataSource = addOns;
            RptAddOns.DataBind();
        }
Пример #2
0
        protected void SaveProductClick(object sender, EventArgs e)
        {
            var  products = new Products();
            var  isNew    = true;
            bool isFeaturedRequired;
            bool isCheckedInRequired;

            if (Request.Params["id"] != "0")
            {
                isNew      = false;
                products   = _products;
                _productId = _products.ProductId;
            }
            else
            {
                products.HotelId  = PublicHotel.HotelId;
                products.IsActive = true;
            }

            int productType = int.Parse(ProductTypeDdl.SelectedValue);

            products.ProductType      = productType;
            products.ProductName      = ProductNameText.Text.Trim();
            products.MaxGuest         = Int16.Parse(HidMaxGuest.Value);
            products.ProductHighlight = ProductHighlightText.Text;
            products.WhatYouGet       = WhatYouGetEditor.Text;
            products.Service          = ServiceEditor.Text;


            bool.TryParse(IsFeaturedRequiredHidden.Value, out isFeaturedRequired);
            products.IsFeatured = isFeaturedRequired;

            products.RedemptionPeriod = Int16.Parse(HidRedemptionPeriod.Value);
            bool.TryParse(IsCheckedInRequiredHidden.Value, out isCheckedInRequired);
            products.IsCheckedInRequired = isCheckedInRequired;

            products.IsKidAllow = Int16.Parse(KidAllowedDdl.SelectedValue);
            // Available Upgrades

            products.MetaDescription = MetaDescription.Text;
            products.MetaKeyword     = MetaKeyword.Text;

            // Photos on tab 4

            var defaultPrice = Mapper.Map <Products, DefaultPrices>(products);

            defaultPrice.UpdatedBy   = 1;
            defaultPrice.UpdatedDate = DateTime.UtcNow;
            if (isNew)
            {
                // Default Value if add new product
                _productId             = _productRepository.Add(products);
                defaultPrice.ProductId = _productId;

                var passLimit = _hotelRepository.GetDailyPassLimit(PublicHotel.HotelId);
                switch (products.ProductType)
                {
                case (int)Enums.ProductType.DayPass:
                    products.DailySales       = passLimit.DailyPass;
                    defaultPrice.DailyDayPass = passLimit.DailyPass;
                    break;

                case (int)Enums.ProductType.Cabana:
                    products.DailySales      = passLimit.CabanaPass;
                    defaultPrice.DailyCabana = passLimit.CabanaPass;
                    break;

                case (int)Enums.ProductType.SpaPass:
                    products.DailySales   = passLimit.SpaPass;
                    defaultPrice.DailySpa = passLimit.SpaPass;
                    break;

                case (int)Enums.ProductType.Daybed:
                    products.DailySales      = passLimit.DaybedPass;
                    defaultPrice.DailyDaybed = passLimit.DaybedPass;
                    break;

                case (int)Enums.ProductType.AddOns:
                    products.DailySales = 0;
                    break;
                }

                defaultPrice.EffectiveDate = DateTime.UtcNow.AddDays(-7);
                _productRepository.AddDefaultPrices(defaultPrice);
            }
            else
            {
                var photos = new List <ProductImages>();
                foreach (ListViewDataItem item in ProductImageListView.Items)
                {
                    //to get the dropdown of each line
                    HiddenField productPhotoId = (HiddenField)item.FindControl("PhotoId");

                    var photo     = _productImageRepository.GetById(int.Parse(productPhotoId.Value));
                    var orderItem = (HiddenField)item.FindControl("Order");
                    photo.Order = 1;
                    if (!string.IsNullOrEmpty(orderItem.Value))
                    {
                        photo.Order    = int.Parse(orderItem.Value);
                        photo.IsCover  = false;
                        photo.IsActive = true;
                    }

                    photos.Add(photo);
                }
                if (photos.FirstOrDefault(p => p.Order == 0 || p.Order == 1) != null)
                {
                    photos.First(p => p.Order == 0 || p.Order == 1).IsCover = true;
                }

                _productImageRepository.Update(photos);

                _productRepository.Update(products);
            }

            string productImageDefault = Constant.ImageDefault;
            var    productImage        = _productImageRepository.GetAll().FirstOrDefault(x => x.ProductId == products.ProductId && x.IsCover && x.IsActive);

            if (productImage != null)
            {
                productImageDefault = productImage.Url;
            }

            if (!string.IsNullOrEmpty(productImageDefault))
            {
                var    imageName = Helper.ReplaceLastOccurrence(productImageDefault, ".", "-ovl.");
                string imageUrl  = Server.MapPath(imageName);
                if (!File.Exists(imageUrl))
                {
                    System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(productImageDefault));
                    Bitmap newImage            = Helper.ChangeOpacity(image, 0.7f);
                    using (MemoryStream memory = new MemoryStream())
                    {
                        using (FileStream fs = new FileStream(imageUrl, FileMode.Create, FileAccess.ReadWrite))
                        {
                            newImage.Save(memory, ImageFormat.Jpeg);
                            byte[] bytes = memory.ToArray();
                            fs.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
            }

            // Delete old records if edit on same day
            _productRepository.DeleteDefaultPrices(_productId, DateTime.UtcNow);

            _productRepository.ResetCache();

            Response.Redirect(Constant.ProductListPage);
        }