コード例 #1
0
        protected virtual void UpdateLocales(NewsItem NewsItem, NewsItemModel entityModel)
        {
            if (entityModel.LanguageId <= 0)
            {
                return;
            }

            entityModel.Locales.Add(new NewsItemLocalizedModel()
            {
                LanguageId = entityModel.LanguageId,
                Name       = entityModel.Name,
            });
            foreach (var localized in entityModel.Locales)
            {
                #region LocalizedProperty

                _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Name, NewsItem.Name, localized.LanguageId);

                _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Short, NewsItem.Short, localized.LanguageId);

                _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Full, NewsItem.Full, localized.LanguageId);

                #endregion

                //search engine name
                //var seName = NewsItem.ValidateSeName(localized.SeName, localized.Name, false);
                //_urlRecordService.SaveSlug(NewsItem, seName, localized.LanguageId);
            }

            VerboseReporter.ReportSuccess("Sửa ngôn ngữ tin tức thành công", "put");
        }
コード例 #2
0
        public ActionResult Create(SlideShowViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string fileName  = Path.GetFileName(model.Image.FileName);
                        string extension = Path.GetExtension(model.Image.FileName);
                        fileName = string.Concat(model.Title.NonAccent(), extension);
                        string str = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.AdsFolder)), fileName);
                        model.Image.SaveAs(str);
                        model.ImgPath = string.Concat(Contains.AdsFolder, fileName);
                    }

                    SlideShow modelMap = Mapper.Map <SlideShowViewModel, SlideShow>(model);
                    this._slideShowService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.SlideShow)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("SlideShow.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(model));
            }
            return(action);
        }
コード例 #3
0
        public ActionResult Create(PaymentMethodViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(View(model));
                }

                if (model.Image != null && model.Image.ContentLength > 0)
                {
                    var fileExtension    = Path.GetExtension(model.Image.FileName);
                    var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName);

                    var fileName = fileNameOriginal.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.PaymentMethodFolder}", fileName, ImageSize.PaymentMethodWithMediumSize, ImageSize.PaymentMethodHeightMediumSize);

                    model.ImageUrl = string.Concat(Contains.PaymentMethodFolder, fileName);
                }

                var modelMap = Mapper.Map <PaymentMethodViewModel, PaymentMethod>(model);
                _paymentMethodService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.PaymentMethodSystemName, localized.PaymentMethodSystemName, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.PaymentMethod)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("PaymentMethod.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(action);
        }
コード例 #4
0
        public ActionResult Create(SlideShowViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);

                    return(View(model));
                }

                ImageHandler(model);

                var modelMap = Mapper.Map <SlideShowViewModel, SlideShow>(model);
                _slideShowService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.SlideShow)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                LogText.Log(string.Concat("SlideShow.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
コード例 #5
0
        public ActionResult Create(GenericControlViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    GenericControl modelMap = Mapper.Map <GenericControlViewModel, App.Domain.Entities.GenericControl.GenericControl>(model);
                    this._genericControlService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Name, localized.Name, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.GenericControl)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("GenericControl.Create: ", exception.Message));
                return(base.View(model));
            }
            return(action);
        }
コード例 #6
0
        public ActionResult Create(PaymentMethodViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", MessageUI.ErrorMessage);
                    return(View(model));
                }

                ImageHandler(model);

                var modelMap = Mapper.Map <PaymentMethodViewModel, PaymentMethod>(model);
                _paymentMethodService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.PaymentMethodSystemName, localized.PaymentMethodSystemName, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.PaymentMethod)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                LogText.Log(string.Concat("PaymentMethod.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(action);
        }
コード例 #7
0
        public ActionResult Create(ContactInformationViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var modelMap = Mapper.Map <ContactInformationViewModel, ContactInformation>(model);
                _contactInfoService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Address, localized.Address, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.ContactInformation)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception exception1)
            {
                var exception = exception1;
                ExtentionUtils.Log(string.Concat("MailSetting.Create: ", exception.Message));
                return(View(model));
            }
            return(action);
        }
コード例 #8
0
        protected virtual void SaveLocalizedValue(Menu service, MenuModel entityModel)
        {
            if (entityModel.LanguageId <= 0)
            {
                return;
            }

            _localizedPropertyService.SaveLocalizedValue(service,
                                                         x => x.Name,
                                                         entityModel.Name,
                                                         entityModel.LanguageId);

            VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "put");
        }
コード例 #9
0
        public ActionResult Create(StaticContentViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    string titleNonAccent = model.Title.NonAccent();
                    IEnumerable <StaticContent> bySeoUrl = this._staticContentService.GetBySeoUrl(titleNonAccent, isCache: false);
                    model.SeoUrl = model.Title.NonAccent();

                    if (bySeoUrl.Any <StaticContent>((StaticContent x) => x.Id != model.Id))
                    {
                        StaticContentViewModel staticContentViewModel = model;
                        staticContentViewModel.SeoUrl = string.Concat(staticContentViewModel.SeoUrl, "-", bySeoUrl.Count <StaticContent>());
                    }

                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string fileName  = Path.GetFileName(model.Image.FileName);
                        string extension = Path.GetExtension(model.Image.FileName);
                        fileName = fileName.FileNameFormat(extension);

                        string str = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName);

                        model.Image.SaveAs(str);
                        model.ImagePath = string.Concat(Contains.ImageFolder, fileName);
                    }

                    if (model.MenuId > 0)
                    {
                        MenuLink menuLink = this._menuLinkService.GetById(model.MenuId, isCache: false);
                        model.MenuLink          = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink);
                        model.VirtualCategoryId = menuLink.VirtualId;
                    }

                    StaticContent modelMap = Mapper.Map <StaticContentViewModel, StaticContent>(model);
                    this._staticContentService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.StaticContent)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("Post.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(model));
            }
            return(action);
        }
コード例 #10
0
        public ActionResult Create(PostViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else //if (!this._postService.FindBy((Post x) => x.ProductCode.Equals(model.ProductCode), true).IsAny<Post>())
                {
                    string             titleNonAccent = model.Title.NonAccent();
                    IEnumerable <Post> bySeoUrl       = this._postService.GetListSeoUrl(titleNonAccent);
                    model.SeoUrl = model.Title.NonAccent();
                    if (bySeoUrl.Any <Post>((Post x) => x.Id != model.Id))
                    {
                        PostViewModel postViewModel = model;
                        postViewModel.SeoUrl = string.Concat(postViewModel.SeoUrl, "-", bySeoUrl.Count <Post>());
                    }

                    string folderName = string.Format("{0:ddMMyyyy}", DateTime.UtcNow);
                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string fileExtension = Path.GetExtension(model.Image.FileName);
                        //string fileName = titleNonAccent.FileNameFormat(extension);

                        string fileName1 = titleNonAccent.FileNameFormat(fileExtension);
                        string fileName2 = titleNonAccent.FileNameFormat(fileExtension);
                        string fileName3 = titleNonAccent.FileNameFormat(fileExtension);

                        _imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, false);
                        _imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName2, ImageSize.WithMediumSize, ImageSize.HeightMediumSize, false);
                        _imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName3, ImageSize.WithSmallSize, ImageSize.HeightSmallSize, false);

                        model.ImageBigSize    = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName1);
                        model.ImageMediumSize = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName2);
                        model.ImageSmallSize  = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName3);
                    }

                    int?menuId = model.MenuId;
                    int i      = 0;
                    if ((menuId.GetValueOrDefault() > i ? menuId.HasValue : false))
                    {
                        IMenuLinkService menuLinkService = this._menuLinkService;
                        menuId = model.MenuId;
                        MenuLink byId = menuLinkService.GetById(menuId.Value);
                        model.VirtualCatUrl     = byId.VirtualSeoUrl;
                        model.VirtualCategoryId = byId.VirtualId;
                    }

                    //Gallery image
                    HttpFileCollectionBase files         = base.Request.Files;
                    List <GalleryImage>    galleryImages = new List <GalleryImage>();
                    if (files.Count > 0)
                    {
                        int      count   = files.Count - 1;
                        int      num     = 0;
                        string   str6    = titleNonAccent;
                        string[] allKeys = files.AllKeys;
                        for (i = 0; i < (int)allKeys.Length; i++)
                        {
                            string str7 = allKeys[i];
                            if (num <= count)
                            {
                                if (!str7.Equals("Image"))
                                {
                                    string             str8 = str7.Replace("[]", "");
                                    HttpPostedFileBase item = files[num];
                                    if (item.ContentLength > 0)
                                    {
                                        string item1 = base.Request[str8];
                                        GalleryImageViewModel galleryImageViewModel = new GalleryImageViewModel()
                                        {
                                            PostId           = model.Id,
                                            AttributeValueId = int.Parse(str8)
                                        };

                                        string fileExtension = Path.GetExtension(model.Image.FileName);
                                        string fileName1     = titleNonAccent.FileNameFormat(fileExtension);
                                        string fileName2     = titleNonAccent.FileNameFormat(fileExtension);

                                        _imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, false);
                                        _imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName2, ImageSize.WithThumbnailSize, ImageSize.HeightThumbnailSize, false);

                                        galleryImageViewModel.ImageThumbnail = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName2);
                                        galleryImageViewModel.ImagePath      = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName1);

                                        galleryImageViewModel.OrderDisplay = num;
                                        galleryImageViewModel.Status       = 1;
                                        galleryImageViewModel.Title        = model.Title;
                                        galleryImageViewModel.Price        = new double?(double.Parse(item1));

                                        galleryImages.Add(Mapper.Map <GalleryImage>(galleryImageViewModel));
                                    }
                                    num++;
                                }
                                else
                                {
                                    num++;
                                }
                            }
                        }
                    }

                    //Attribute
                    List <AttributeValue> attributeValues = new List <AttributeValue>();
                    string item2 = base.Request["Values"];
                    if (!string.IsNullOrEmpty(item2))
                    {
                        foreach (string list in item2.Split(new char[] { ',' }).ToList <string>())
                        {
                            int num1 = int.Parse(list);
                            attributeValues.Add(this._attributeValueService.GetById(num1));
                        }
                    }

                    Post modelMap = Mapper.Map <PostViewModel, Post>(model);
                    if (galleryImages.IsAny <GalleryImage>())
                    {
                        modelMap.GalleryImages = galleryImages;
                    }
                    if (attributeValues.IsAny <AttributeValue>())
                    {
                        modelMap.AttributeValues = attributeValues;
                    }

                    this._postService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ProductCode, localized.ProductCode, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.TechInfo, localized.TechInfo, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.SeoUrl, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Post)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
                //else
                //{
                //	base.ModelState.AddModelError("", "Mã sản phẩm đã tồn tại.");
                //	action = base.View(model);
                //}
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("Post.Create: ", ex.Message));
                base.ModelState.AddModelError("", ex.Message);

                return(base.View(model));
            }
            return(action);
        }
コード例 #11
0
        public ActionResult Create(StaticContentViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                        .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _staticContentService.GetBySeoUrl(titleNonAccent, false);
                model.SeoUrl = model.Title.NonAccent();

                if (bySeoUrl.Any(x => x.Id != model.Id))
                {
                    var staticContentViewModel = model;
                    staticContentViewModel.SeoUrl = Concat(staticContentViewModel.SeoUrl, "-", bySeoUrl.Count());
                }

                if (model.Image != null && model.Image.ContentLength > 0)
                {
                    var folderName       = Utils.FolderName(model.Title);
                    var fileExtension    = Path.GetExtension(model.Image.FileName);
                    var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName);

                    var fileName = fileNameOriginal.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.StaticContentFolder}{folderName}/", fileName, ImageSize.StaticContentWithBigSize, ImageSize.StaticContentHeightBigSize, true);

                    model.ImagePath = $"{Contains.StaticContentFolder}{folderName}/{fileName}";

                    //var fileName = Path.GetFileName(model.Image.FileName);
                    //var extension = Path.GetExtension(model.Image.FileName);
                    //fileName = fileName.FileNameFormat(extension);

                    //var str = Path.Combine(Server.MapPath(Concat("~/", Contains.StaticContentFolder)), fileName);

                    //model.Image.SaveAs(str);
                    //model.ImagePath = Concat(Contains.StaticContentFolder, fileName);
                }

                if (model.MenuId > 0)
                {
                    var menuLink = _menuLinkService.GetById(model.MenuId, false);
                    model.MenuLink          = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink);
                    model.VirtualCategoryId = menuLink.VirtualId;
                }

                var modelMap = Mapper.Map <StaticContentViewModel, StaticContent>(model);
                _staticContentService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", Format(MessageUI.CreateSuccess, FormUI.StaticContent)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(Concat("StaticContent.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }
            return(action);
        }
コード例 #12
0
        public ActionResult Create(SystemSettingViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    if (model.Status == 1)
                    {
                        IEnumerable <SystemSetting> systemSettings = this._systemSettingService.FindBy((SystemSetting x) => x.Status == 1, false);
                        if (systemSettings.IsAny <SystemSetting>())
                        {
                            foreach (SystemSetting systemSetting1 in systemSettings)
                            {
                                systemSetting1.Status = 0;
                                this._systemSettingService.Update(systemSetting1);
                            }
                        }
                    }

                    if (model.Favicon != null && model.Favicon.ContentLength > 0)
                    {
                        string fileName  = Path.GetFileName(model.Favicon.FileName);
                        string extension = Path.GetExtension(model.Favicon.FileName);
                        fileName = string.Concat("favicon", extension);
                        string str = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName);

                        //Check and delete logo exists
                        if (System.IO.File.Exists(str))
                        {
                            System.IO.File.Delete(str);
                        }

                        model.Favicon.SaveAs(str);
                        model.FaviconImage = string.Concat(Contains.ImageFolder, fileName);
                    }

                    if (model.Logo != null && model.Logo.ContentLength > 0)
                    {
                        string fileName  = Path.GetFileName(model.Logo.FileName);
                        string extension = Path.GetExtension(model.Logo.FileName);
                        fileName = string.Concat("logo", extension);
                        string str = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName);

                        //Check and delete logo exists
                        if (System.IO.File.Exists(str))
                        {
                            System.IO.File.Delete(str);
                        }

                        model.Logo.SaveAs(str);
                        model.LogoImage = string.Concat(Contains.ImageFolder, fileName);
                    }

                    SystemSetting modelMap = Mapper.Map <SystemSettingViewModel, SystemSetting>(model);
                    this._systemSettingService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.FooterContent, localized.FooterContent, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.TimeWork, localized.TimeWork, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Slogan, localized.Slogan, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.SystemSetting)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("SystemSetting.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(model));
            }
            return(action);
        }
コード例 #13
0
ファイル: NewsController.cs プロジェクト: cong1389/ThienPhat
        public ActionResult Create(NewsViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    string             str      = model.Title.NonAccent();
                    IEnumerable <News> bySeoUrl = this._newsService.GetBySeoUrl(str);
                    model.SeoUrl = model.Title.NonAccent();
                    if (bySeoUrl.Any <News>((News x) => x.Id != model.Id))
                    {
                        NewsViewModel newsViewModel = model;
                        newsViewModel.SeoUrl = string.Concat(newsViewModel.SeoUrl, "-", bySeoUrl.Count <News>());
                    }
                    string str1 = string.Format("{0:ddMMyyyy}", DateTime.UtcNow);
                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string str2 = string.Concat(str, ".jpg");
                        string str3 = string.Format("{0}-{1}.jpg", str, Guid.NewGuid());
                        string str4 = string.Format("{0}-{1}.jpg", str, Guid.NewGuid());
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.NewsFolder, str1), str2, new int?(ImageSize.WithBigSize), new int?(ImageSize.HeightBigSize), false);
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.NewsFolder, str1), str3, new int?(ImageSize.WithMediumSize), new int?(ImageSize.HeightMediumSize), false);
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.NewsFolder, str1), str4, new int?(ImageSize.WithSmallSize), new int?(ImageSize.HeightSmallSize), false);
                        model.ImageBigSize    = string.Format("{0}{1}/{2}", Contains.NewsFolder, str1, str2);
                        model.ImageMediumSize = string.Format("{0}{1}/{2}", Contains.NewsFolder, str1, str3);
                        model.ImageSmallSize  = string.Format("{0}{1}/{2}", Contains.NewsFolder, str1, str4);
                    }
                    if (model.MenuId > 0)
                    {
                        MenuLink byId = this._menuLinkService.GetById(model.MenuId);
                        model.VirtualCatUrl     = byId.VirtualSeoUrl;
                        model.VirtualCategoryId = byId.VirtualId;
                    }
                    News modelMap = Mapper.Map <NewsViewModel, News>(model);
                    this._newsService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.News)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("Post.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(model));
            }
            return(action);
        }
コード例 #14
0
        public ActionResult Create(MenuLinkViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var menuName   = model.MenuName.NonAccent();
                var menuExsist = _menuLinkService.GetListSeoUrl(menuName);
                model.SeoUrl = model.MenuName.NonAccent();

                if (menuExsist.Any(x => x.Id != model.Id))
                {
                    var menuLinkViewModel = model;
                    var seoUrl            = menuLinkViewModel.SeoUrl;
                    var num = menuExsist.Count();
                    menuLinkViewModel.SeoUrl = string.Concat(seoUrl, "-", num.ToString());
                }

                ImageHandler(model);

                var guid = Guid.NewGuid().ToString();
                if (model.ParentId.HasValue)
                {
                    model.CurrentVirtualId = guid;
                    var byId = _menuLinkService.GetMenu(model.ParentId.Value);
                    model.VirtualId     = $"{byId.VirtualId}/{guid}";
                    model.VirtualSeoUrl = $"{byId.SeoUrl}/{model.SeoUrl}";
                }
                else
                {
                    model.VirtualId        = guid;
                    model.CurrentVirtualId = guid;
                }

                var modelMap = Mapper.Map <MenuLinkViewModel, MenuLink>(model);
                _menuLinkService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MenuName, localized.MenuName, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.MenuName.NonAccent(), localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.MenuLink)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                LogText.Log(string.Concat("MenuLink.Create: ", ex.Message));

                return(View(model));
            }
            return(action);
        }
コード例 #15
0
        public ActionResult Create(PostViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _postService.GetListSeoUrl(titleNonAccent);

                model.SeoUrl = model.Title.NonAccent();
                if (bySeoUrl.Any(x => x.Id != model.Id))
                {
                    var postViewModel = model;
                    postViewModel.SeoUrl = string.Concat(postViewModel.SeoUrl, "-", bySeoUrl.Count());
                }

                var folderName = Utils.FolderName(model.Title);
                if (model.Image != null && model.Image.ContentLength > 0)
                {
                    var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName);
                    var fileExtension    = Path.GetExtension(model.Image.FileName);

                    var fileName1 = fileNameOriginal.FileNameFormat(fileExtension);
                    var fileName2 = fileNameOriginal.FileNameFormat(fileExtension);
                    var fileName3 = fileNameOriginal.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.PostFolder}{folderName}/", fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, true);
                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.PostFolder}{folderName}/", fileName2, ImageSize.WithMediumSize, ImageSize.HeightMediumSize, true);
                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.PostFolder}{folderName}/", fileName3, ImageSize.WithSmallSize, ImageSize.HeightSmallSize, true);

                    model.ImageBigSize    = $"{Contains.PostFolder}{folderName}/{fileName1}";
                    model.ImageMediumSize = $"{Contains.PostFolder}{folderName}/{fileName2}";
                    model.ImageSmallSize  = $"{Contains.PostFolder}{folderName}/{fileName3}";
                }

                var menuId = model.MenuId;
                var i      = 0;
                if (menuId.GetValueOrDefault() > i && menuId.HasValue)
                {
                    var menuLinkService = _menuLinkService;
                    menuId = model.MenuId;
                    var byId = menuLinkService.GetById(menuId.Value);
                    model.VirtualCatUrl     = byId.VirtualSeoUrl;
                    model.VirtualCategoryId = byId.VirtualId;
                }

                //Gallery image
                var files         = Request.Files;
                var galleryImages = new List <GalleryImage>();
                if (files.Count > 0)
                {
                    var count   = files.Count - 1;
                    var num     = 0;
                    var allKeys = files.AllKeys;
                    for (i = 0; i < allKeys.Length; i++)
                    {
                        var str7 = allKeys[i];
                        if (num <= count)
                        {
                            if (!str7.Equals("Image"))
                            {
                                var str8 = str7.Replace("[]", "");
                                var item = files[num];
                                if (item.ContentLength > 0)
                                {
                                    var item1 = Request[str8];
                                    var galleryImageViewModel = new GalleryImageViewModel
                                    {
                                        PostId           = model.Id,
                                        AttributeValueId = int.Parse(str8)
                                    };

                                    var fileNameOriginal = Path.GetFileNameWithoutExtension(item.FileName);
                                    var fileExtension    = Path.GetExtension(item.FileName);

                                    var fileName1 = $"attr.{ fileNameOriginal}".FileNameFormat(fileExtension);
                                    var fileName2 = $"attr.{ fileNameOriginal}".FileNameFormat(fileExtension);

                                    _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, true);
                                    _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName2, ImageSize.WithThumbnailSize, ImageSize.HeightThumbnailSize, true);

                                    galleryImageViewModel.ImageBig       = $"{Contains.PostFolder}{folderName}/{fileName1}";
                                    galleryImageViewModel.ImageThumbnail = $"{Contains.PostFolder}{folderName}/{fileName2}";

                                    galleryImageViewModel.OrderDisplay = num;
                                    galleryImageViewModel.Status       = 1;
                                    galleryImageViewModel.Title        = model.Title;
                                    galleryImageViewModel.Price        = double.Parse(item1);

                                    galleryImages.Add(Mapper.Map <GalleryImage>(galleryImageViewModel));
                                }
                                num++;
                            }
                            else
                            {
                                num++;
                            }
                        }
                    }
                }

                //Attribute
                var attributeValues = new List <AttributeValue>();
                var item2           = Request["Values"];
                if (!string.IsNullOrEmpty(item2))
                {
                    foreach (var list in item2.Split(',').ToList())
                    {
                        var num1 = int.Parse(list);
                        attributeValues.Add(_attributeValueService.GetById(num1));
                    }
                }

                var modelMap = Mapper.Map <PostViewModel, Post>(model);
                if (galleryImages.IsAny())
                {
                    modelMap.GalleryImages = galleryImages;
                }
                if (attributeValues.IsAny())
                {
                    modelMap.AttributeValues = attributeValues;
                }

                _postService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ProductCode, localized.ProductCode, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.TechInfo, localized.TechInfo, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.SeoUrl, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Post)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
                //else
                //{
                //	base.ModelState.AddModelError("", "Mã sản phẩm đã tồn tại.");
                //	action = base.View(model);
                //}
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("Post.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }
            return(action);
        }
コード例 #16
0
        public ActionResult Create(SystemSettingViewModel model, string returnUrl)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                        .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                if (model.Status == 1)
                {
                    var systemSettings = _systemSettingService.FindBy(x => x.Status == 1);
                    if (systemSettings.IsAny())
                    {
                        foreach (var item in systemSettings)
                        {
                            item.Status = 0;
                            _systemSettingService.Update(item);
                        }
                    }
                }

                if (model.Favicon != null && model.Favicon.ContentLength > 0)
                {
                    var extension = Path.GetExtension(model.Favicon.FileName);
                    var fileName  = Concat("favicon", extension);
                    var path      = Path.Combine(Server.MapPath(Concat("~/", Constant.SystemSettingFolder)), fileName);

                    //Check and delete logo exists
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    model.Favicon.SaveAs(path);
                    model.FaviconImage = Concat(Constant.SystemSettingFolder, fileName);
                }

                if (model.Logo != null && model.Logo.ContentLength > 0)
                {
                    var extension = Path.GetExtension(model.Logo.FileName);
                    var fileName  = Concat("logo", extension);
                    var path      = Path.Combine(Server.MapPath(Concat("~/", Constant.SystemSettingFolder)), fileName);

                    //Check and delete logo exists
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    model.Logo.SaveAs(path);
                    model.LogoImage = Concat(Constant.SystemSettingFolder, fileName);
                }

                if (model.LogoFooter != null && model.LogoFooter.ContentLength > 0)
                {
                    var extension = Path.GetExtension(model.LogoFooter.FileName);
                    var fileName  = Concat("logoFooter", extension);
                    var path      = Path.Combine(Server.MapPath(Concat("~/", Constant.SystemSettingFolder)), fileName);

                    //Check and delete logo exists
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    model.LogoFooter.SaveAs(path);
                    model.LogoFooterImage = Concat(Constant.SystemSettingFolder, fileName);
                }

                var modelMap = Mapper.Map <SystemSettingViewModel, SystemSetting>(model);
                _systemSettingService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.FooterContent, localized.FooterContent, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.TimeWork, localized.TimeWork, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Slogan, localized.Slogan, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", Format(MessageUI.CreateSuccess, FormUI.SystemSetting)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    return(RedirectToAction("Index"));
                }

                return(Redirect(returnUrl));
            }
            catch (Exception ex)
            {
                LogText.Log(Concat("SystemSetting.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }
        }
コード例 #17
0
        public ActionResult Create(MenuLinkViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    string str = model.MenuName.NonAccent();
                    IEnumerable <MenuLink> bySeoUrl = this._menuLinkService.GetListSeoUrl(str);
                    model.SeoUrl = model.MenuName.NonAccent();
                    if (bySeoUrl.Any <MenuLink>((MenuLink x) => x.Id != model.Id))
                    {
                        MenuLinkViewModel menuLinkViewModel = model;
                        string            seoUrl            = menuLinkViewModel.SeoUrl;
                        int num = bySeoUrl.Count <MenuLink>();
                        menuLinkViewModel.SeoUrl = string.Concat(seoUrl, "-", num.ToString());
                    }
                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string fileName  = Path.GetFileName(model.Image.FileName);
                        string extension = Path.GetExtension(model.Image.FileName);
                        fileName = string.Concat(model.MenuName.NonAccent(), extension);
                        string str1 = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName);
                        model.Image.SaveAs(str1);
                        model.ImageUrl = string.Concat(Contains.ImageFolder, fileName);
                    }
                    if (model.ImageIcon1 != null && model.ImageIcon1.ContentLength > 0)
                    {
                        string fileName1  = Path.GetFileName(model.ImageIcon1.FileName);
                        string extension1 = Path.GetExtension(model.ImageIcon1.FileName);
                        fileName1 = string.Concat(string.Concat(model.MenuName, "-icon").NonAccent(), extension1);
                        string str2 = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName1);
                        model.ImageIcon1.SaveAs(str2);
                        model.Icon1 = string.Concat(Contains.ImageFolder, fileName1);
                    }
                    if (model.ImageIcon2 != null && model.ImageIcon2.ContentLength > 0)
                    {
                        string fileName2  = Path.GetFileName(model.ImageIcon2.FileName);
                        string extension2 = Path.GetExtension(model.ImageIcon2.FileName);
                        fileName2 = string.Concat(string.Concat(model.MenuName, "-iconbar").NonAccent(), extension2);
                        string str3 = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName2);
                        model.ImageIcon2.SaveAs(str3);
                        model.Icon2 = string.Concat(Contains.ImageFolder, fileName2);
                    }
                    if (model.ParentId.HasValue)
                    {
                        string str4 = Guid.NewGuid().ToString();
                        model.CurrentVirtualId = str4;
                        MenuLink byId = this._menuLinkService.GetById(model.ParentId.Value);
                        model.VirtualId     = string.Format("{0}/{1}", byId.VirtualId, str4);
                        model.VirtualSeoUrl = string.Format("{0}/{1}", byId.SeoUrl, model.SeoUrl);
                    }
                    else
                    {
                        string str5 = Guid.NewGuid().ToString();
                        model.VirtualId        = str5;
                        model.CurrentVirtualId = str5;
                    }

                    MenuLink modelMap = Mapper.Map <MenuLinkViewModel, MenuLink>(model);
                    this._menuLinkService.Create(modelMap);

                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MenuName, localized.MenuName, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.MenuName.NonAccent(), localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.MenuLink)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("MailSetting.Create: ", exception.Message));
                return(base.View(model));
            }
            return(action);
        }
コード例 #18
0
ファイル: NewsController.cs プロジェクト: cong1389/KuteShop
        public ActionResult Create(NewsViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _newsService.GetBySeoUrl(titleNonAccent);
                model.SeoUrl = model.Title.NonAccent();
                if (bySeoUrl.Any(x => x.Id != model.Id))
                {
                    var newsViewModel = model;
                    newsViewModel.SeoUrl = string.Concat(newsViewModel.SeoUrl, "-", bySeoUrl.Count());
                }

                ImageHandler(model);

                if (model.MenuId > 0)
                {
                    var byId = _menuLinkService.GetMenu(model.MenuId, false);
                    model.VirtualCatUrl     = byId.VirtualSeoUrl;
                    model.VirtualCategoryId = byId.VirtualId;
                }

                var modelMap = Mapper.Map <NewsViewModel, News>(model);
                _newsService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.News)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                LogText.Log(string.Concat("News.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(action);
        }
コード例 #19
0
        public ActionResult Create(MenuLinkViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var menuName = model.MenuName.NonAccent();
                var bySeoUrl = _menuLinkService.GetListSeoUrl(menuName);
                model.SeoUrl = model.MenuName.NonAccent();

                if (bySeoUrl.Any(x => x.Id != model.Id))
                {
                    var menuLinkViewModel = model;
                    var seoUrl            = menuLinkViewModel.SeoUrl;
                    var num = bySeoUrl.Count();
                    menuLinkViewModel.SeoUrl = string.Concat(seoUrl, "-", num.ToString());
                }

                var folderName = Utils.FolderName(model.MenuName);
                if (model.ImageBigSizeFile != null && model.ImageBigSizeFile.ContentLength > 0)
                {
                    var fileName       = Path.GetFileNameWithoutExtension(model.ImageBigSizeFile.FileName);
                    var fileExtension  = Path.GetExtension(model.ImageBigSizeFile.FileName);
                    var fileNameFormat = fileName.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.ImageBigSizeFile, $"{Contains.MenuFolder}{folderName}/", fileNameFormat, ImageSize.MenuWithBigSize, ImageSize.MenuHeightBigSize, true);
                    model.ImageBigSize = $"{Contains.MenuFolder}{folderName}/{fileNameFormat}";
                }

                if (model.ImageMediumSizeFile != null && model.ImageMediumSizeFile.ContentLength > 0)
                {
                    var fileName       = Path.GetFileNameWithoutExtension(model.ImageMediumSizeFile.FileName);
                    var fileExtension  = Path.GetExtension(model.ImageMediumSizeFile.FileName);
                    var fileNameFormat = fileName.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.ImageMediumSizeFile, $"{Contains.MenuFolder}{folderName}/", fileNameFormat, ImageSize.MenuWithMediumSize, ImageSize.MenuHeightMediumSize, true);
                    model.ImageMediumSize = $"{Contains.MenuFolder}{folderName}/{fileNameFormat}";
                }

                if (model.ImageSmallSizeFile != null && model.ImageSmallSizeFile.ContentLength > 0)
                {
                    var fileName       = Path.GetFileNameWithoutExtension(model.ImageSmallSizeFile.FileName);
                    var fileExtension  = Path.GetExtension(model.ImageSmallSizeFile.FileName);
                    var fileNameFormat = fileName.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.ImageSmallSizeFile, $"{Contains.MenuFolder}{folderName}/", fileNameFormat, ImageSize.MenuWithSmallSize, ImageSize.MenuHeightSmallSize, true);
                    model.ImageSmallSize = $"{Contains.MenuFolder}{folderName}/{fileNameFormat}";
                }

                var guid = Guid.NewGuid().ToString();
                if (model.ParentId.HasValue)
                {
                    model.CurrentVirtualId = guid;
                    var byId = _menuLinkService.GetById(model.ParentId.Value);
                    model.VirtualId     = $"{byId.VirtualId}/{guid}";
                    model.VirtualSeoUrl = $"{byId.SeoUrl}/{model.SeoUrl}";
                }
                else
                {
                    model.VirtualId        = guid;
                    model.CurrentVirtualId = guid;
                }

                var modelMap = Mapper.Map <MenuLinkViewModel, MenuLink>(model);
                _menuLinkService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MenuName, localized.MenuName, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.MenuName.NonAccent(), localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.MenuLink)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("MenuLink.Create: ", ex.Message));

                return(View(model));
            }
            return(action);
        }
コード例 #20
0
        public ActionResult Create(SlideShowViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);

                    return(View(model));
                }

                if (model.Image != null && model.Image.ContentLength > 0)
                {
                    var folderName       = Utils.FolderName(model.Title);
                    var fileExtension    = Path.GetExtension(model.Image.FileName);
                    var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName);

                    var fileName = fileNameOriginal.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.SlideShowFolder}{folderName}/", fileName, ImageSize.SlideShowWithBigSize, ImageSize.SlideShowHeightBigSize, true);

                    model.ImgPath = $"{Contains.SlideShowFolder}{folderName}/{fileName}";

                    //var fileExtension = Path.GetExtension(model.Image.FileName);

                    //var fileName = model.Title.NonAccent().FileNameFormat(fileExtension);

                    //var imageServerPath = Path.Combine(Server.MapPath(string.Concat("~/", Contains.AdsFolder)), fileName);

                    //model.ImgPath = $"{Contains.AdsFolder}/{fileName}";
                    //model.Image.SaveAs(imageServerPath);
                }

                var modelMap = Mapper.Map <SlideShowViewModel, SlideShow>(model);
                _slideShowService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.SlideShow)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(string.Concat("SlideShow.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
コード例 #21
0
        public ActionResult Create(NewsViewModel model, string returnUrl)
        {
            ActionResult action;

            try
            {
                if (!ModelState.IsValid)
                {
                    var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(v => v.ErrorMessage + " " + v.Exception));
                    ModelState.AddModelError("", messages);
                    return(View(model));
                }

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _newsService.GetBySeoUrl(titleNonAccent);
                model.SeoUrl = model.Title.NonAccent();
                if (bySeoUrl.Any(x => x.Id != model.Id))
                {
                    var newsViewModel = model;
                    newsViewModel.SeoUrl = string.Concat(newsViewModel.SeoUrl, "-", bySeoUrl.Count());
                }

                var folderName = Utils.FolderName(model.Title);
                if (model.Image != null && model.Image.ContentLength > 0)
                {
                    var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName);
                    var fileExtension    = Path.GetExtension(model.Image.FileName);

                    var fileName1 = fileNameOriginal.FileNameFormat(fileExtension);
                    var fileName2 = fileNameOriginal.FileNameFormat(fileExtension);
                    var fileName3 = fileNameOriginal.FileNameFormat(fileExtension);

                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.NewsFolder}{folderName}/", fileName1, ImageSize.NewsWithBigSize, ImageSize.NewsHeightBigSize);
                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.NewsFolder}{folderName}/", fileName2, ImageSize.NewsWithMediumSize, ImageSize.NewsHeightMediumSize);
                    _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.NewsFolder}{folderName}/", fileName3, ImageSize.NewsWithSmallSize, ImageSize.NewsHeightSmallSize);

                    model.ImageBigSize    = $"{Contains.NewsFolder}{folderName}/{fileName1}";
                    model.ImageMediumSize = $"{Contains.NewsFolder}{folderName}/{fileName2}";
                    model.ImageSmallSize  = $"{Contains.NewsFolder}{folderName}/{fileName3}";
                }

                if (model.MenuId > 0)
                {
                    var byId = _menuLinkService.GetById(model.MenuId, false);
                    model.VirtualCatUrl     = byId.VirtualSeoUrl;
                    model.VirtualCategoryId = byId.VirtualId;
                }

                var modelMap = Mapper.Map <NewsViewModel, News>(model);
                _newsService.Create(modelMap);

                //Update Localized
                foreach (var localized in model.Locales)
                {
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId);
                    _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.News)));
                if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                {
                    action = RedirectToAction("Index");
                }
                else
                {
                    action = Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("News.Create: ", ex.Message));
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(action);
        }