Пример #1
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);
        }
Пример #2
0
 public ActionResult EditPost(PostViewModel postView)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             ModelState.AddModelError("", MessageUI.ErrorMessage);
         }
         else
         {
             var byId     = _postService.GetById(postView.Id);
             var str      = postView.Title.NonAccent();
             var bySeoUrl = _menuLinkService.GetListSeoUrl(str);
             postView.SeoUrl = postView.Title.NonAccent();
             if (bySeoUrl.Any(x => x.Id != postView.Id))
             {
                 var postViewModel = postView;
                 postViewModel.SeoUrl = string.Concat(postViewModel.SeoUrl, "-", bySeoUrl.Count());
             }
             var files = Request.Files;
             if (postView.Image != null && postView.Image.ContentLength > 0)
             {
                 var str1 = $"{str}-{Utils.GetTime()}";
                 var str2 = $"{str}-{Utils.GetTime()}";
                 var str3 = $"{str}-{Utils.GetTime()}";
                 _imagePlugin.CropAndResizeImage(postView.Image, $"{Contains.PostFolder}/{str}/", str1, ImageSize.WithBigSize, ImageSize.HeightBigSize);
                 _imagePlugin.CropAndResizeImage(postView.Image, $"{Contains.PostFolder}/{str}/", str2, ImageSize.WithMediumSize, ImageSize.HeightMediumSize);
                 _imagePlugin.CropAndResizeImage(postView.Image, $"{Contains.PostFolder}/{str}/", str3, ImageSize.WithSmallSize, ImageSize.HeightSmallSize);
                 postView.ImageBigSize    = $"{Contains.PostFolder}/{str}/{str1}";
                 postView.ImageMediumSize = $"{Contains.PostFolder}/{str}/{str2}";
                 postView.ImageSmallSize  = $"{Contains.PostFolder}/{str}/{str3}";
             }
             var menuId = postView.MenuId;
             var i      = 0;
             if (menuId.GetValueOrDefault() > i && menuId.HasValue)
             {
                 var menuLinkService = _menuLinkService;
                 menuId = postView.MenuId;
                 var menuLink = menuLinkService.GetById(menuId.Value);
                 postView.VirtualCatUrl     = menuLink.VirtualSeoUrl;
                 postView.VirtualCategoryId = menuLink.VirtualId;
             }
             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 str4 = allKeys[i];
                     if (num <= count)
                     {
                         if (!str4.Equals("ImageBigSize"))
                         {
                             var item = files[num];
                             if (item.ContentLength > 0)
                             {
                                 var galleryImageViewModel = new GalleryImageViewModel
                                 {
                                     PostId = postView.Id
                                 };
                                 var str5 = $"{str}-{Utils.GetTime()}";
                                 var str6 = $"{str}-{Utils.GetTime()}";
                                 _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}/{str}/", str5, ImageSize.WithOrignalSize, ImageSize.HeighthOrignalSize);
                                 _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}/{str}/", str6, ImageSize.WithThumbnailSize, ImageSize.HeightThumbnailSize);
                                 galleryImageViewModel.ImageThumbnail = $"{Contains.PostFolder}/{str}/{str6}";
                                 galleryImageViewModel.ImageBig       = $"{Contains.PostFolder}/{str}/{str5}";
                                 galleryImageViewModel.OrderDisplay   = num;
                                 galleryImageViewModel.Status         = 1;
                                 galleryImageViewModel.Title          = postView.Title;
                                 galleryImages.Add(Mapper.Map <GalleryImage>(galleryImageViewModel));
                             }
                             num++;
                         }
                         else
                         {
                             num++;
                         }
                     }
                 }
             }
             if (galleryImages.IsAny())
             {
                 byId.GalleryImages = galleryImages;
             }
             byId = Mapper.Map(postView, byId);
             _postService.Update(byId);
             ViewBag.Message = "Cập nhật tin rao thành công";
             return(View(postView));
         }
     }
     catch (Exception exception1)
     {
         var exception = exception1;
         ModelState.AddModelError("", exception.Message);
         ExtentionUtils.Log(string.Concat("Post.Edit: ", exception.Message));
     }
     ViewBag.Message = "Cập nhật tin rao KHÔNG thành công";
     return(View(postView));
 }
Пример #3
0
        public ActionResult Edit(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 byId = _newsService.GetById(model.Id, false);

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _menuLinkService.GetListSeoUrl(titleNonAccent, false);
                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 menuLink = _menuLinkService.GetById(model.MenuId, false);
                    model.VirtualCatUrl     = menuLink.VirtualSeoUrl;
                    model.VirtualCategoryId = menuLink.VirtualId;
                    model.MenuLink          = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink);
                }

                var modelMap = Mapper.Map(model, byId);
                _newsService.Update(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.UpdateSuccess, 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)
            {
                ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(string.Concat("News.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
Пример #4
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);
        }
        public ActionResult Edit(StaticContentViewModel model, string returnUrl)
        {
            ActionResult action;

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

                var byId = _staticContentService.GetById(model.Id, false);

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _menuLinkService.GetListSeoUrl(titleNonAccent, false);
                model.SeoUrl = titleNonAccent;

                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 extension = Path.GetExtension(model.Image.FileName);
                    //var fileName = titleNonAccent.FileNameFormat(extension);

                    //model.Image.SaveAs(Path.Combine(Server.MapPath(Concat("~/", Contains.StaticContentFolder)), fileName));
                    //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(model, byId);
                _staticContentService.Update(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.UpdateSuccess, 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)
            {
                ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(Concat("StaticContent.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
Пример #6
0
        public ActionResult Edit(StaticContentViewModel model, string returnUrl)
        {
            ActionResult action;

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

                var byId = _staticContentService.GetById(model.Id, false);

                var titleNonAccent = model.Title.NonAccent();
                var bySeoUrl       = _menuLinkService.GetListSeoUrl(titleNonAccent, false);
                model.SeoUrl = titleNonAccent;

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

                ImageHandler(model);

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

                var modelMap = Mapper.Map(model, byId);
                _staticContentService.Update(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.UpdateSuccess, 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)
            {
                ModelState.AddModelError("", ex.Message);
                LogText.Log(Concat("StaticContent.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
Пример #7
0
        public ActionResult Edit(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));
                }

                if (!_postService.FindBy(x => x.ProductCode.Equals(model.ProductCode) && x.Id != model.Id, true).IsAny())
                {
                    var byId = _postService.GetById(model.Id, false);

                    var titleNonAccent = model.Title.NonAccent();
                    var bySeoUrl       = _menuLinkService.GetListSeoUrl(titleNonAccent, false);

                    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 menuLink = menuLinkService.GetById(menuId.Value, false);
                        model.VirtualCatUrl     = menuLink.VirtualSeoUrl;
                        model.VirtualCategoryId = menuLink.VirtualId;
                    }

                    //GalleryImage
                    var files            = Request.Files;
                    var lstGalleryImages = 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 fileNameOrginal = Path.GetFileNameWithoutExtension(item.FileName);
                                        var fileExtension   = Path.GetExtension(item.FileName);

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

                                        _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName1, ImageSize.WithBigSize, ImageSize.WithBigSize, 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);

                                        lstGalleryImages.Add(Mapper.Map <GalleryImage>(galleryImageViewModel));
                                    }
                                    num++;
                                }
                                else
                                {
                                    num++;
                                }
                            }
                        }
                    }
                    if (lstGalleryImages.IsAny())
                    {
                        byId.GalleryImages = lstGalleryImages;
                    }

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

                        if (nums.IsAny())
                        {
                            (
                                from x in byId.AttributeValues
                                where !nums.Contains(x.Id)
                                select x).ToList().ForEach(att => byId.AttributeValues.Remove(att));
                        }
                    }

                    byId.AttributeValues = lstAttributeValues;

                    var modelMap = Mapper.Map(model, byId);
                    _postService.Update(byId);

                    //Update GalleryImage
                    if (lstAttributeValues.IsAny())
                    {
                        foreach (var attributeValue in lstAttributeValues)
                        {
                            var nullable = _galleryService.Get(x => x.AttributeValueId == attributeValue.Id && x.PostId == model.Id);
                            if (nullable == null)
                            {
                                continue;
                            }
                            var request = Request;
                            i = attributeValue.Id;
                            var num2 = decimal.Parse(request[i.ToString()]);
                            nullable.Price = num2;
                            _galleryService.Update(nullable);
                        }
                    }

                    //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.UpdateSuccess, FormUI.Post)));
                    if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\"))
                    {
                        action = RedirectToAction("Index");
                    }
                    else
                    {
                        action = Redirect(returnUrl);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Mã sản phẩm đã tồn tại.");
                    action = View(model);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(string.Concat("Post.Edit: ", ex.Message));

                return(View(model));
            }

            return(action);
        }