Esempio n. 1
0
        public ActionResult Edit(InteProductModels model)
        {
            try
            {
                //model.ListStoreView = model.ListStoreView.Where(x => x.Selected).ToList();
                var lListStoreSel = model.ListStoreView.Where(x => x.Selected).ToList();
                if (lListStoreSel.Count == 0)
                {
                    ModelState.AddModelError("ListStoreView", (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store")));
                }

                model.ListProductOnStore = model.ListProductOnStore.Where(x => x.Status != (byte)Commons.EStatus.Deleted).ToList();
                if (model.ListProductOnStore != null && model.ListProductOnStore.Count > 0)
                {
                    model.ListStoreView.ForEach(z =>
                    {
                        var isCheck = model.ListProductOnStore.Exists(x => x.StoreID.Equals(z.Value) && x.IsDeleteTemplate);
                        z.Selected  = isCheck;
                    });

                    foreach (var itemProduct in model.ListProductOnStore)
                    {
                        if (itemProduct.ListPrices[0].Price < 0)
                        {
                            ModelState.AddModelError("ListProductOnStore[" + itemProduct.OffSet + "].ListPrices[0].Price", (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please input default price greater than 0")));
                        }
                        else
                        {
                            if (itemProduct.Cost > itemProduct.ListPrices[0].Price)
                            {
                                ModelState.AddModelError("ListProductOnStore[" + itemProduct.OffSet + "].ListPrices[0].Price", (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Default Price must be larger than cost")));
                            }
                        }

                        for (int i = 1; i < itemProduct.ListPrices.Count; i++)
                        {
                            if (itemProduct.ListPrices[i].Price > 0 && string.IsNullOrEmpty(itemProduct.ListPrices[i].SeasonID))
                            {
                                ModelState.AddModelError(string.Format("ListProductOnStore[" + itemProduct.OffSet + "].ListPrices[{0}].Price", i), (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please select Season for Price")));
                            }
                        }

                        for (int i = 1; i < itemProduct.ListPrices.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(itemProduct.ListPrices[i].SeasonID) && itemProduct.ListPrices[i].Price < 0)
                            {
                                ModelState.AddModelError(string.Format("ListProductOnStore[" + itemProduct.OffSet + "].ListPrices[{0}].Price", i), (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please input price greater than 0")));
                            }
                        }

                        // ============
                        if (itemProduct.ExpiredDate == null)
                        {
                            itemProduct.ExpiredDate = Commons._ExpiredDate;
                        }
                        else
                        {
                            itemProduct.ExpiredDate = new DateTime(itemProduct.ExpiredDate.Value.Year,
                                                                   itemProduct.ExpiredDate.Value.Month, itemProduct.ExpiredDate.Value.Day, 12, 59, 59);
                        }

                        if (itemProduct.HasServiceCharge)
                        {
                            //if (string.IsNullOrEmpty(itemProduct.sServiceCharge))
                            //    itemProduct.sServiceCharge = "0";
                            //itemProduct.ServiceChargeValue = double.Parse(itemProduct.sServiceCharge ?? "0");
                            //if (itemProduct.ServiceChargeValue < 0)
                            //    ModelState.AddModelError("sServiceCharge", "Please input service charge greater than 0");
                            //else if (itemProduct.ServiceChargeValue > 100)
                            //    ModelState.AddModelError("sServiceCharge", "Maximum service charge is 100%");
                        }
                        else
                        {
                            itemProduct.ServiceChargeValue = -1;
                        }

                        if (string.IsNullOrEmpty(itemProduct.CategoryID))
                        {
                            ModelState.AddModelError("ListProductOnStore[" + itemProduct.OffSet + "].CategoryID", (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose category")));
                        }

                        // Updated 08282017
                        string cateIdChoose = null;
                        if (!string.IsNullOrEmpty(itemProduct.CategoryID))
                        {
                            cateIdChoose = itemProduct.CategoryID;
                        }

                        itemProduct.IsOptional = true;
                        itemProduct.IsForce    = true;

                        InteProductPriceModels proPrice = new InteProductPriceModels()
                        {
                            DefaultPrice  = Math.Round(itemProduct.ListPrices[0].Price, 2),
                            SeasonPrice   = Math.Round(itemProduct.ListPrices[1].Price, 2),
                            SeasonPriceID = itemProduct.ListPrices[1].SeasonID
                        };
                        itemProduct.PriceOnStore = proPrice;
                        itemProduct.ColorCode    = "#000000";
                        itemProduct.PrintOutName = itemProduct.PrintOutName;
                        itemProduct.Measure      = String.IsNullOrEmpty(itemProduct.Measure) ? "$" : itemProduct.Measure;
                        //=================
                        //Return Data
                        itemProduct.ListPrices     = GetPrices(itemProduct.ListPrices, itemProduct.StoreID);
                        itemProduct.ListCategories = GetSelectListCategoriesInte(itemProduct.StoreID, Commons.EProductType.Modifier.ToString("d"));

                        // Updated 08282017
                        itemProduct.lstCateGroup = GetSelectListCategoriesInteSortParent(itemProduct.StoreID, Commons.EProductType.Modifier.ToString("d"));
                        if (!string.IsNullOrEmpty(cateIdChoose))
                        {
                            var cateChoose = itemProduct.lstCateGroup.Where(w => w.Id == cateIdChoose).FirstOrDefault();
                            if (cateChoose != null)
                            {
                                cateChoose.Selected = true;
                            }
                        }
                    }
                }


                if (!ModelState.IsValid)
                {
                    if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    {
                        model.ImageURL = "";
                    }
                    //Return Data
                    //model = GetDetail(model.ID);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                //=====
                byte[] photoByte = null;
                if (!string.IsNullOrEmpty(model.ImageURL))
                {
                    model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, "");
                }
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }
                else
                {
                    model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, "");
                }
                //====================
                model.ProductType = (byte)Commons.EProductType.Modifier;
                //=============
                string msg = "";
                var    tmp = model.PictureByte;
                model.PictureByte = null;
                var result = _factory.InsertOrUpdateProduct(model, CurrentUser.UserId, ref msg);
                if (result)
                {
                    model.PictureByte = tmp;
                    //Save Image on Server
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);
                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                        model.PictureByte = photoByte;
                        FTP.Upload(model.ImageURL, model.PictureByte);
                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Name", msg);
                    //model = GetDetail(model.ID);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Product_Modifier_Edit: " + ex);
                //return new HttpStatusCodeResult(400, ex.Message);
                ModelState.AddModelError("Name", (_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have an error")));
                //model = GetDetail(model.ID);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Edit", model));
            }
        }
Esempio n. 2
0
        /*POnS*/
        public ActionResult AddMoreProductItemOnStore(int currentOffset, string StoreID, string StoreName)
        {
            InteProductItemOnStore model        = new InteProductItemOnStore();
            InteProductPriceModels PriceOnStore = new InteProductPriceModels();

            model.OffSet         = currentOffset;
            model.StoreName      = StoreName;
            model.StoreID        = StoreID;
            model.CurrencySymbol = CurrentUser.CurrencySymbol;
            //================Price
            SeasonFactory         seasonf          = new SeasonFactory();
            List <SeasonModels>   lstSs            = seasonf.GetListSeason(model.StoreID, null, CurrentUser.ListOrganizationId);
            List <SelectListItem> lstSllItemSeason = new List <SelectListItem>();
            SelectListItem        sslItemSeason;

            foreach (var season in lstSs)
            {
                sslItemSeason          = new SelectListItem();
                sslItemSeason.Value    = season.ID;
                sslItemSeason.Text     = season.Name;
                sslItemSeason.Selected = season.ID.Equals(PriceOnStore.SeasonPriceID);
                lstSllItemSeason.Add(sslItemSeason);
            }
            foreach (PriceItem priceItem in model.ListPrices)
            {
                priceItem.ListSeasons = lstSllItemSeason;
            }
            if (model.ListPrices != null && model.ListPrices.Count > 0)
            {
                model.ListPrices[0].Price    = PriceOnStore.DefaultPrice;
                model.ListPrices[1].Price    = PriceOnStore.SeasonPrice == -1 ? 0 : PriceOnStore.SeasonPrice;
                model.ListPrices[1].SeasonID = null;//PriceOnStore.SeasonPriceID;

                model.ListPrices[0].StoreID = model.StoreID;
                model.ListPrices[1].StoreID = model.StoreID;
            }

            //======Category
            model.ListCategories = this.GetSelectListCategoriesInte(StoreID, Commons.EProductType.Modifier.ToString("d"));

            // Updated 08282017
            model.lstCateGroup = this.GetSelectListCategoriesInteSortParent(StoreID, Commons.EProductType.Modifier.ToString("d"));
            if (!string.IsNullOrEmpty(model.CategoryID))
            {
                var cateChoose = model.lstCateGroup.Where(w => w.Id == model.CategoryID).FirstOrDefault();
                if (cateChoose != null)
                {
                    cateChoose.Selected = true;
                }
            }

            //============ LoadServiceCharge
            var objServiceCharge = _tipServiceChargeFactory.GetListTipServiceCharge(model.StoreID);

            if (objServiceCharge != null && objServiceCharge.Count > 0)
            {
                var value            = objServiceCharge[0].Value;
                var IsCurrency       = objServiceCharge[0].IsCurrency;
                var IsIncludedOnBill = objServiceCharge[0].IsIncludedOnBill;
                model.sServiceCharge = value.ToString();
                if (!IsCurrency)
                {
                    //$('#chbServiceCharge').attr('disabled', false);
                    model.ServiceChargeDisabled = false;
                }
                else if (IsCurrency || IsIncludedOnBill)
                {
                    //$('#chbServiceCharge').attr('disabled', true);
                    model.ServiceChargeDisabled = true;
                }
            }
            //==============
            return(PartialView("_ProductItemOnStore", model));
        }
Esempio n. 3
0
        public InteProductModels GetDetail(string id)
        {
            try
            {
                InteProductModels model = _factory.GetProductDetail(id);
                model.ImageURL       = string.IsNullOrEmpty(model.ImageURL) ? Commons.Image100_100 : model.ImageURL;
                model.CurrencySymbol = CurrentUser.CurrencySymbol;
                //var lstStore = (List<SelectListItem>)ViewBag.ListStore;
                //model.ListStoreView = lstStore;
                var lstStore = (SelectList)ViewBag.StoreID;
                model.ListStoreView = lstStore.ToList();
                model.ListStoreView = model.ListStoreView.OrderBy(o => o.Text).ToList();
                int OffSet = 0;
                if (model.ListProductOnStore != null && model.ListProductOnStore.Count > 0)
                {
                    model.ListProductOnStore = model.ListProductOnStore.OrderBy(oo => oo.StoreName).ToList();
                    foreach (var item in model.ListProductOnStore)
                    {
                        item.CurrencySymbol   = model.CurrencySymbol;
                        item.CurrencySymbol   = CurrentUser.CurrencySymbol;
                        item.OffSet           = OffSet++;
                        item.IsDeleteTemplate = true;
                        item.ExpiredDate      = item.ExpiredDate.Value.ToLocalTime();
                        if (item.ExpiredDate == Commons._ExpiredDate)
                        {
                            item.ExpiredDate = null;
                        }
                        model.ListStoreView.ForEach(x =>
                        {
                            if (!x.Selected)
                            {
                                x.Selected = x.Value.Equals(item.StoreID) ? true : false;
                                x.Disabled = x.Selected;
                            }
                        });
                        //===========
                        InteProductPriceModels PriceOnStore = item.PriceOnStore == null ? new InteProductPriceModels() : item.PriceOnStore;
                        if (item.ListProductGroup != null)
                        {
                            List <InteGroupProductModels> groupP = item.ListProductGroup;
                            for (int i = 0; i < item.ListProductGroup.Count; i++)
                            {
                                item.ListProductGroup[i].OffSet      = i;
                                item.ListProductGroup[i].StoreOffSet = item.OffSet;
                                item.ListProductGroup[i].StoreID     = item.StoreID;
                                if (item.ListProductGroup[i].ListProductOnGroup != null)
                                {
                                    for (int j = 0; j < item.ListProductGroup[i].ListProductOnGroup.Count; j++)
                                    {
                                        item.ListProductGroup[i].ListProductOnGroup[j].OffSet = j;
                                    }
                                }
                            }
                        }
                        //item.sServiceCharge = item.ServiceChargeValue == -1 ? "" : item.ServiceChargeValue.ToString();
                        //================ Get Category
                        item.ListCategories = this.GetSelectListCategoriesInte(item.StoreID, Commons.EProductType.Modifier.ToString("d"));

                        // Updated 08282017
                        item.lstCateGroup = this.GetSelectListCategoriesInteSortParent(item.StoreID, Commons.EProductType.Modifier.ToString("d"));
                        if (!string.IsNullOrEmpty(item.CategoryID))
                        {
                            var cateChoose = item.lstCateGroup.Where(w => w.Id == item.CategoryID).FirstOrDefault();
                            if (cateChoose != null)
                            {
                                cateChoose.Selected = true;
                            }
                        }

                        //================Price
                        SeasonFactory         seasonf          = new SeasonFactory();
                        List <SeasonModels>   lstSs            = seasonf.GetListSeason(item.StoreID, null, CurrentUser.ListOrganizationId);
                        List <SelectListItem> lstSllItemSeason = new List <SelectListItem>();
                        SelectListItem        sslItemSeason;
                        foreach (var season in lstSs)
                        {
                            sslItemSeason          = new SelectListItem();
                            sslItemSeason.Value    = season.ID;
                            sslItemSeason.Text     = season.Name;
                            sslItemSeason.Selected = season.ID.Equals(PriceOnStore.SeasonPriceID);
                            lstSllItemSeason.Add(sslItemSeason);
                        }
                        foreach (PriceItem priceItem in item.ListPrices)
                        {
                            priceItem.ListSeasons = lstSllItemSeason;
                        }
                        item.ListPrices[0].Price    = PriceOnStore.DefaultPrice;
                        item.ListPrices[1].Price    = PriceOnStore.SeasonPrice == -1 ? 0 : PriceOnStore.SeasonPrice;
                        item.ListPrices[1].SeasonID = PriceOnStore.SeasonPriceID;
                        item.ListPrices[1].PriceTag = PriceOnStore.SeasonPriceName;
                    }
                }
                return(model);
            }
            catch (Exception ex)
            {
                _logger.Error("Product_Modifier_Detail: " + ex);
                return(null);
            }
        }