コード例 #1
0
ファイル: SliderController.cs プロジェクト: ArDotWeb/eShop
        public virtual ActionResult CreateSlider(ShowSliderViewModel sliderViewModel)
        {
            var file = Request.Files[0];

            if (file != null && file.ContentLength > 0)
            {
                string fileName = string.Empty;
                using (var img = Image.FromStream(file.InputStream))
                {
                    fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Slider/"), file.FileName);
                    TODO.UploadImage(img, new Size(900, 350), Server.MapPath("~/Content/Images/Slider/"), fileName);
                }

                var slider = new Slider {
                    Address = sliderViewModel.AddressSlider, Explain = sliderViewModel.ExplainSlider, Image = fileName, Title = sliderViewModel.TitleSlider
                };
                _sliderService.Create(slider);
                if (_unitOfWork.SaveAllChanges() > 0)
                {
                    TempData["createSlider"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessInsert), Status = AlertMode.success
                    });
                    return(RedirectToAction(actionName: MVC.admin.Slider.ActionNames.CreateSlider));
                }
                else
                {
                    TempData["createSlider"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                    });
                }
            }

            return(View());
        }
コード例 #2
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 }));
            }
        }
コード例 #3
0
ファイル: CategoryController.cs プロジェクト: ArDotWeb/eShop
        public virtual ActionResult UpdateCategory(CategoryEditViewModel model)
        {
            var category = new Category();

            if (model.Parent_Id > 0)
            {
                var parentCategory = _categoryService.GetById(model.Parent_Id);
                category.Parent = parentCategory;
            }
            else
            {
                category.Parent = null;
            }
            category.Id   = model.Id;
            category.Name = model.Name;

            _categoryService.Update(category);

            if (_unitOfWork.SaveAllChanges() > 0)
            {
                return(RedirectToAction(actionName: MVC.admin.Category.ActionNames.DetailsCategory, routeValues: new { Id = model.Id }));
            }
            else
            {
                TempData["updateCategory"] = Helperalert.alert(new AlertViewModel
                {
                    Alert  = AlertOperation.SurveyOperation(StatusOperation.DuplicateName),
                    Status = AlertMode.info
                });
                return(RedirectToAction(actionName: MVC.admin.Category.ActionNames.UpdateCategory,
                                        routeValues: new { Id = model.Id }));
            }
        }
コード例 #4
0
        public virtual async Task <ActionResult> Login(LoginViewModel model, string ReturnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    if (!user.DisableUser)
                    {
                        var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

                        switch (result)
                        {
                        case SignInStatus.Failure:
                            return(Json(new { Result = Helperalert.alert(new AlertViewModel {
                                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailLogin), Status = AlertMode.warning
                                }).ToString(), Status = false }, JsonRequestBehavior.AllowGet));

                        case SignInStatus.LockedOut:
                            return(null);

                        // return Json(new { Result = Helperalert.alert(new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.DuplicateName), Status = AlertMode.info }).ToString(), Status = false, Redirect = "Home/Index" }, JsonRequestBehavior.AllowGet);
                        case SignInStatus.RequiresVerification:
                            return(null);

                        case SignInStatus.Success:
                            return(Json(new { Result = Helperalert.alert(new AlertViewModel {
                                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccessLogin), Status = AlertMode.success
                                }).ToString(), Status = true, Redirect = (string.IsNullOrEmpty(ReturnUrl)) ? HttpContext.Request.UrlReferrer.AbsolutePath : ReturnUrl }, JsonRequestBehavior.AllowGet));

                        //HttpContext.Request.UrlReferrer.AbsolutePath
                        default:
                            return(null);
                        }
                    }
                    else
                    {
                        return(Json(new { Result = Helperalert.alert(new AlertViewModel {
                                Alert = AlertOperation.SurveyOperation(StatusOperation.DisableUser), Status = AlertMode.warning
                            }).ToString(), Status = false, Redirect = "Home/Index" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { Result = Helperalert.alert(new AlertViewModel {
                            Alert = AlertOperation.SurveyOperation(StatusOperation.NoExistUser), Status = AlertMode.info
                        }).ToString(), Status = false }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { Result = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.Invalid), Status = AlertMode.info
                    }).ToString(), Status = false }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
ファイル: CompanyController.cs プロジェクト: ArDotWeb/eShop
        public virtual ActionResult CreateCompany(CompanyAddViewModel model)
        {
            //1048576 Bytes == 1024 * 1024 KB == 1 MB ---> 1024
            if (ModelState.IsValid)
            {
                try
                {
                    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/Company/"), model.Image.FileName);
                                TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName);
                                model.ImageLogo = fileName;
                            }
                        }
                    }


                    model.Title = HelperTitle.GetTitle(Address: model.Address);

                    var company = new Company {
                        Address = model.Address, ImageLogo = model.ImageLogo, Explain = model.Explain, Name = model.Name, Title = model.Title
                    };
                    _companyService.Create(company);
                    if (_unitOfWork.SaveAllChanges() > 0)
                    {
                        return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = company.Id }));
                    }
                    else
                    {
                        TempData["createCompany"] = Helperalert.alert(new AlertViewModel {
                            Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                        });
                        return(View());
                    }
                }
                catch
                {
                    TempData["createCompany"] = Helperalert.alert(new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                    });
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
コード例 #6
0
        public virtual ActionResult CreateImageProduct(IEnumerable <HttpPostedFileBase> ImageProductAdditinal, int Id)
        {
            var model            = _productService.GetById(Id: Id);
            var imageProductList = new List <ImageProduct>();

            foreach (var item in ImageProductAdditinal)
            {
                if (item != null)
                {
                    if (item.ContentLength > 0)
                    {
                        using (var img = Image.FromStream(item.InputStream))
                        {
                            string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Product/GallerySize/"), item.FileName);

                            TODO.UploadImage(img, new Size(600, 600), Server.MapPath("~/Content/Images/Product/GallerySize/"), fileName);
                            imageProductList.Add(new ImageProduct {
                                Image = fileName, Product = model
                            });
                        }
                    }
                }
            }
            _unitOfWork.AddRange <ImageProduct>(imageProductList);

            if (_unitOfWork.SaveAllChanges() > 0)
            {
                return(RedirectToAction(actionName: MVC.admin.Product.ActionNames.ShowImageProduct, routeValues: new { Id = Id }));
            }
            else
            {
                TempData["createImageProduct"] = Helperalert.alert(new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.Dependencies), Status = AlertMode.info
                });
                return(RedirectToAction(MVC.admin.Product.ActionNames.CreateImageProduct, new { Id = Id }));
            }
        }
コード例 #7
0
ファイル: CompanyController.cs プロジェクト: ArDotWeb/eShop
        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));
            }
        }
コード例 #8
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 }));
            }
        }
コード例 #9
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 }));
            }
        }
コード例 #10
0
        public virtual ActionResult CreateProduct(ProductViewModel model, IEnumerable <HttpPostedFileBase> ImageProductAdditinal)
        {
            var product = new Product()
            {
                Explain = model.Explain, Category = _categoryService.GetById(model.Category_Id), Company = _companyService.GetById(model.Company_Id), Name = model.Name, Labels = _labelService.GetLabelsByIds(model.Labels), Time = model.Time, Date = model.Date, VisitNumber = 0, Price = model.Price, Recomend = 1, ModifiedDate = DateTime.Now
            };

            //save primary image with 3 size
            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/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;
                    }
                }
            }

            //save other image for this prduct
            var listImage = new List <ImageProduct>();

            foreach (var item in ImageProductAdditinal)
            {
                if (item != null && item.ContentLength > 0)
                {
                    string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Product/GallerySize/"), model.Image.FileName);

                    TODO.UploadImage(Image.FromStream(item.InputStream), new Size(450, 450), Server.MapPath("~/Content/Images/Product/GallerySize/"), fileName);
                    listImage.Add(new ImageProduct {
                        Image = fileName, Product = product
                    });
                }
            }


            product.ImageProducts = listImage;
            _productService.Create(product);

            if (_unitOfWork.SaveAllChanges() > 0)
            {
                //For Use Notification With SignalR
                //Response Redirect To Main Page In Site
                //return RedirectToAction(MVC.admin.Product.ActionNames.DetailsProduct, new { Id = product.Id });
                if (Request.Cookies["Cart"] != null)
                {
                    HttpCookie cookie = Request.Cookies["Cart"];
                    cookie.Value   = "true";
                    cookie.Expires = DateTime.Now.AddMinutes(2);
                    System.Web.HttpContext.Current.Response.Cookies.Set(cookie);
                }
                else
                {
                    HttpCookie cookie = new HttpCookie("Alert");
                    cookie.Value   = "true";
                    cookie.Expires = DateTime.Now.AddMinutes(2);
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
                }

                LuceneProductSearch.AddUpdateLuceneIndex(new LuceneProductModel
                {
                    Product_Id      = product.Id,
                    Product_Name    = product.Name,
                    Product_Explain = product.Explain.Length > 400 ?
                                      product.Explain.ToSafeHtml().RemoveHtmlTags().Substring(0, 400) :
                                      product.Explain.ToSafeHtml().RemoveHtmlTags()
                });

                return(RedirectToRoute("DetailsProduct", new { productId = product.Id, productName = UrlExtensions.ResolveTitleForUrl(product.Name) }));
            }
            else
            {
                TempData["createProduct"] = Helperalert.alert(new AlertViewModel {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning
                });
                return(RedirectToAction(MVC.admin.Product.ActionNames.CreateProduct));
            }
        }