Ejemplo n.º 1
0
        public virtual ActionResult DeleteImageProduct(List <string> checkboxImage, int Id)
        {
            var list    = new List <ImageProduct>();
            var address = Server.MapPath("~/Content/Images/Product/GallerySize/");

            foreach (var item in checkboxImage)
            {
                list.Add(new ImageProduct {
                    Id = int.Parse(item.Split('/')[0])
                });
                TODO.DeleteImage(Path.Combine(address, item.Split('/')[1]));
            }

            _unitOfWork.RemoveRange <ImageProduct>(list);
            if (_unitOfWork.SaveAllChanges() > 0)
            {
                //Remove Id From Document
                LuceneProductSearch.ClearLuceneIndexRecord(Id);
                return(RedirectToAction(actionName: MVC.admin.Product.ActionNames.DetailsProduct, routeValues: new { Id = Id }));
            }
            else
            {
                ViewData["deleteImageProduct"] = Helperalert.alert(new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.Dependencies), Status = AlertMode.info
                });
                return(RedirectToAction(MVC.admin.Product.ActionNames.DeleteImageProduct, new { Id = Id }));
            }
        }
Ejemplo n.º 2
0
        public virtual ActionResult DeleteImageSlider(List <string> checkboxImage)
        {
            var listId   = new List <Slider>();
            var listName = new List <string>();

            foreach (var item in checkboxImage)
            {
                listId.Add(new Slider {
                    Id = int.Parse(item.Split('/')[0])
                });
                listName.Add(item.Split('/')[1]);
            }
            _unitOfWork.RemoveRange <Slider>(listId);
            if (_unitOfWork.SaveAllChanges() > 0)
            {
                foreach (var item in listName)
                {
                    TODO.DeleteImage(Server.MapPath("~/Content/Images/Slider/" + item));
                }
                return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessDelete),
                    Status = AlertMode.success
                }));
            }
            else
            {
                return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailDelete),
                    Status = AlertMode.warning
                }));
            }
        }
Ejemplo n.º 3
0
        public virtual PartialViewResult DelteCompany(int Id)
        {
            var    company = _companyService.GetById(Id: Id);
            string address = Server.MapPath("~/Content/Images/Company/");

            if (_productService.GetByCompanyId(company.Id))
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.Dependencies),
                    Status = AlertMode.warning
                }));
            }
            else
            {
                _companyService.Delete(company);
                if (_unitOfWork.SaveAllChanges() > 0)
                {
                    TODO.DeleteImage(Path.Combine(address, company.ImageLogo));

                    return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                    {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessDelete),
                        Status = AlertMode.success
                    }));
                }
                else
                {
                    return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                    {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailDelete),
                        Status = AlertMode.warning
                    }));
                }
            }
        }
Ejemplo n.º 4
0
        public virtual ActionResult UpdateCompany(CompanyEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var    company = _companyService.GetById(model.Id);
                string address = Server.MapPath("~/Content/Images/Company/");

                if (model.Image == null)
                {
                    if (company.ImageLogo != null)
                    {
                        TODO.DeleteImage(Path.Combine(address, company.ImageLogo));
                    }
                    company.ImageLogo = null;
                }
                else
                {
                    if (company.ImageLogo == null)
                    {
                    }
                    else
                    {
                        TODO.DeleteImage(Path.Combine(address, company.ImageLogo));
                    }

                    if (model.Image.ContentLength > 0)
                    {
                        using (var img = Image.FromStream(model.Image.InputStream))
                        {
                            string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Company/"), model.Image.FileName);
                            TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName);
                            company.ImageLogo = fileName;
                        }
                    }
                }

                company.Explain = model.Explain;
                company.Name    = model.Name;

                if (company.Address != model.Address)
                {
                    company.Title   = HelperTitle.GetTitle(Address: model.Address);
                    company.Address = model.Address;
                }
                _companyService.Update(company);
                if (_unitOfWork.SaveAllChanges() > 0)
                {
                    return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = model.Id }));
                }
                else
                {
                    TempData["updateCompany"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.warning
                    });
                    return(View());
                }
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 5
0
        public virtual ActionResult UpdatePackage(PackageEditViewModel model)
        {
            var address = Server.MapPath("~/Content/Images/Package/");
            var package = _packageService.GetById(model.Id);

            if (package.Image != null)
            {
                if (model.Image != null)
                {
                    TODO.DeleteImage(Path.Combine(Server.MapPath("~/Content/Images/Package/") + package.Image));

                    if (model.Image.ContentLength > 0)
                    {
                        using (var img = Image.FromStream(model.Image.InputStream))
                        {
                            string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Package/"), model.Image.FileName);
                            TODO.UploadImage(img, new Size(255, 162), Server.MapPath("~/Content/Images/Package/"), fileName);
                            package.Image = fileName;
                        }
                    }
                }
            }
            else
            {
                if (model.Image != null)
                {
                    if (model.Image.ContentLength > 0)
                    {
                        using (var img = Image.FromStream(model.Image.InputStream))
                        {
                            string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Package/"), model.Image.FileName);
                            TODO.UploadImage(img, new Size(255, 162), Server.MapPath("~/Content/Images/Package/"), fileName);
                            package.Image = fileName;
                        }
                    }
                }
            }

            package.Explain       = model.Explain;
            package.IsShow        = model.IsShow;
            package.Name          = model.Name;
            package.DisCountPrice = model.DisCountPrice;
            package.Percent       = model.Percent;
            package.StartDate     = model.StartDate;
            package.EndDate       = model.EndDate;


            _packageService.Update(package);

            if (_unitOfWork.SaveAllChanges() > 0)
            {
                return(RedirectToAction(MVC.admin.Package.ActionNames.DetailsDataPackage, new { Id = model.Id }));
            }
            else
            {
                TempData["updatePackage"] = Helperalert.alert(new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.info
                });
                return(RedirectToAction(MVC.admin.Package.ActionNames.UpdatePackage, new { id = model.Id }));
            }
        }
Ejemplo n.º 6
0
        public virtual ActionResult UpdateProduct(ProductEditViewModel model, string _PrimryImage)
        {
            var product = _productService.GetById(model.Id);

            if (model.Image != null)
            {
                if (model.Image.ContentLength > 0)
                {
                    //delete with 3 address
                    TODO.DeleteImage(Path.Combine(Server.MapPath("~/Content/Images/Product/MainSize/") + _PrimryImage));
                    TODO.DeleteImage(Path.Combine(Server.MapPath("~/Content/Images/Product/ThumbLine_New/") + _PrimryImage));
                    TODO.DeleteImage(Path.Combine(Server.MapPath("~/Content/Images/Product/ThumbLine_Offer") + _PrimryImage));

                    //add with 3 address
                    using (var img = Image.FromStream(model.Image.InputStream))
                    {
                        string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Product/MainSize/"), model.Image.FileName);

                        TODO.UploadImage(img, new Size(180, 180), Server.MapPath("~/Content/Images/Product/MainSize/"), fileName);
                        TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Product/ThumbLine_New/"), fileName);
                        TODO.UploadImage(img, new Size(60, 75), Server.MapPath("~/Content/Images/Product/ThumbLine_Offer"), fileName);
                        product.PrimryImage = fileName;
                    }
                }
            }

            product.Explain = model.Explain; product.Name = model.Name; product.Time = model.Time; product.Date = model.Date; product.Price = model.Price; product.Company = _companyService.GetById(model.Company_Id); product.Category = _categoryService.GetById(model.Category_Id);

            product.Labels.Clear();
            product.Labels = null;
            if (model.LabelsId != null)
            {
                var labels = _labelService.GetLabelsByIds(model.LabelsId);
                product.Labels = labels;
            }
            else
            {
                product.Labels = null;
            }

            product.ModifiedDate = DateTime.Now;

            _productService.Update(product);
            if (_unitOfWork.SaveAllChanges() > 0)
            {
                //Remove Id From Document
                LuceneProductSearch.ClearLuceneIndexRecord(model.Id);

                //Add New Document
                LuceneProductSearch.AddUpdateLuceneIndex(new LuceneProductModel
                {
                    Product_Id      = model.Id,
                    Product_Explain = model.Explain.ToSafeHtml().RemoveHtmlTags(),
                    Product_Name    = model.Name
                });

                return(RedirectToAction(actionName: MVC.admin.Product.ActionNames.DetailsProduct, routeValues: new { Id = model.Id }));
            }
            else
            {
                TempData["createProduct"] = Helperalert.alert(new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.warning
                });
                return(RedirectToAction(actionName: MVC.admin.Product.ActionNames.UpdateProduct, routeValues: new { Id = model.Id }));
            }
        }