Пример #1
0
        public JsonResult GetByMenuId(int menuId, int entityId)
        {
            var lstValueResponse = new List <ControlValueItemResponse>();

            var menuLink = _menuLinkService.GetById(menuId);

            if (menuLink != null)
            {
                var ieGc = menuLink.GenericControls;
                if (ieGc.IsAny())
                {
                    lstValueResponse.AddRange(from item in ieGc
                                              from gcValue in item.GenericControlValues.Where(m => m.Status == (int)Status.Enable)
                                              select new ControlValueItemResponse
                    {
                        GenericControlValueId = gcValue.Id,
                        Name      = gcValue.ValueName,
                        ValueName = gcValue.GetValueItem(entityId)
                    });
                }
            }

            var jsonResult = Json(
                new
            {
                success = lstValueResponse.Any(),
                list    = this.RenderRazorViewToString("_PostDetail.Attribute", lstValueResponse)
            },
                JsonRequestBehavior.AllowGet);

            return(jsonResult);
        }
Пример #2
0
        public ActionResult DeleteOne(int id)
        {
            try
            {
                MenuLink menuLink = _menuLinkService.GetById(id);

                this._menuLinkService.Delete(menuLink);
            }
            catch (Exception ex)
            {
                ExtentionUtils.Log(string.Concat("MenuLink.DeleteById: ", ex.Message));

                base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.ErrorMessageWithFormat, ex.Message)));
            }
            return(base.RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult GetFixItemContent(int id)
        {
            var menuLink = _menuLinkService.GetById(id);

            ViewBag.ImgUrl   = menuLink.ImageBigSize;
            ViewBag.TitleFix = menuLink.MenuName;

            var menuLinks = _menuLinkService.GetByOption(parentId: new List <int> {
                id
            }, isDisplayHomePage: true);

            if (!menuLinks.IsAny())
            {
                return(Json(new { data = "", success = true }
                            , JsonRequestBehavior.AllowGet));
            }

            return(Json(new { data = this.RenderRazorViewToString("_PartialFixItemContent", menuLinks), success = true },
                        JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public JsonResult GetByMenuId(int menuId, int entityId)
        {
            List <ControlValueItemResponse> lstValueResponse = new List <ControlValueItemResponse>();

            MenuLink menuLink = _menuLinkService.GetById(menuId);

            if (menuLink != null)
            {
                IEnumerable <GenericControl> ieGC = menuLink.GenericControls;
                if (ieGC.IsAny())
                {
                    foreach (GenericControl item in ieGC)
                    {
                        IEnumerable <GenericControlValue> gCVDefault = item.GenericControlValues.Where(m => m.Status == 1);
                        //if (gCVDefault.IsAny())
                        //    break;

                        foreach (var gcValue in gCVDefault)
                        {
                            ControlValueItemResponse objValueResponse = new ControlValueItemResponse();

                            objValueResponse.GenericControlValueId = gcValue.Id;
                            objValueResponse.Name      = gcValue.ValueName;
                            objValueResponse.ValueName = gcValue.GetValueItem(entityId);

                            lstValueResponse.Add(objValueResponse);
                        }
                    }
                }
            }

            JsonResult jsonResult = Json(
                new
            {
                success = lstValueResponse.Count() > 0,
                list    = this.RenderRazorViewToString("_CreateOrUpdate.GenericControlValue", lstValueResponse)
            },
                JsonRequestBehavior.AllowGet);

            return(jsonResult);
        }
Пример #5
0
 public ActionResult CreatePost(PostViewModel post)
 {
     try
     {
         if (!base.ModelState.IsValid)
         {
             base.ModelState.AddModelError("", MessageUI.ErrorMessage);
         }
         else
         {
             string             str      = post.Title.NonAccent();
             IEnumerable <Post> bySeoUrl = this._postService.GetBySeoUrl(str);
             post.SeoUrl = post.Title.NonAccent();
             if (bySeoUrl.Any <Post>((Post x) => x.Id != post.Id))
             {
                 PostViewModel postViewModel = post;
                 postViewModel.SeoUrl = string.Concat(postViewModel.SeoUrl, "-", bySeoUrl.Count <Post>());
             }
             if (post.Image != null && post.Image.ContentLength > 0)
             {
                 string str1 = string.Format("{0}-{1}", str, App.Utils.Utils.GetTime());
                 string str2 = string.Format("{0}-{1}", str, App.Utils.Utils.GetTime());
                 string str3 = string.Format("{0}-{1}", str, App.Utils.Utils.GetTime());
                 this._imagePlugin.CropAndResizeImage(post.Image, string.Format("{0}/{1}/", Contains.PostFolder, str), str1, new int?(ImageSize.WithBigSize), new int?(ImageSize.HeightBigSize), false);
                 this._imagePlugin.CropAndResizeImage(post.Image, string.Format("{0}/{1}/", Contains.PostFolder, str), str2, new int?(ImageSize.WithMediumSize), new int?(ImageSize.HeightMediumSize), false);
                 this._imagePlugin.CropAndResizeImage(post.Image, string.Format("{0}/{1}/", Contains.PostFolder, str), str3, new int?(ImageSize.WithSmallSize), new int?(ImageSize.HeightSmallSize), false);
                 post.ImageBigSize    = string.Format("{0}/{1}/{2}", Contains.PostFolder, str, str1);
                 post.ImageMediumSize = string.Format("{0}/{1}/{2}", Contains.PostFolder, str, str2);
                 post.ImageSmallSize  = string.Format("{0}/{1}/{2}", Contains.PostFolder, str, str3);
             }
             int?menuId = post.MenuId;
             int i      = 0;
             if ((menuId.GetValueOrDefault() > i ? menuId.HasValue : false))
             {
                 IMenuLinkService menuLinkService = this._menuLinkService;
                 menuId = post.MenuId;
                 MenuLink byId = menuLinkService.GetById(menuId.Value);
                 post.VirtualCatUrl     = byId.VirtualSeoUrl;
                 post.VirtualCategoryId = byId.VirtualId;
             }
             HttpFileCollectionBase files         = base.Request.Files;
             List <GalleryImage>    galleryImages = null;
             if (files.Count > 0)
             {
                 galleryImages = new List <GalleryImage>();
                 int      count   = files.Count - 1;
                 int      num     = 0;
                 string[] allKeys = files.AllKeys;
                 for (i = 0; i < (int)allKeys.Length; i++)
                 {
                     string str4 = allKeys[i];
                     if (num <= count)
                     {
                         if (!str4.Equals("Image"))
                         {
                             HttpPostedFileBase item = files[num];
                             if (item.ContentLength > 0)
                             {
                                 GalleryImageViewModel galleryImageViewModel = new GalleryImageViewModel()
                                 {
                                     PostId = post.Id
                                 };
                                 string str5 = string.Format("{0}-{1}", str, App.Utils.Utils.GetTime());
                                 string str6 = string.Format("{0}-{1}", str, App.Utils.Utils.GetTime());
                                 this._imagePlugin.CropAndResizeImage(item, string.Format("{0}/{1}/", Contains.PostFolder, str), str5, new int?(ImageSize.WithOrignalSize), new int?(ImageSize.HeighthOrignalSize), false);
                                 this._imagePlugin.CropAndResizeImage(item, string.Format("{0}/{1}/", Contains.PostFolder, str), str6, new int?(ImageSize.WithThumbnailSize), new int?(ImageSize.HeightThumbnailSize), false);
                                 galleryImageViewModel.ImageThumbnail = string.Format("{0}/{1}/{2}", Contains.PostFolder, str, str6);
                                 galleryImageViewModel.ImagePath      = string.Format("{0}/{1}/{2}", Contains.PostFolder, str, str5);
                                 galleryImageViewModel.OrderDisplay   = num;
                                 galleryImageViewModel.Status         = 1;
                                 galleryImageViewModel.Title          = post.Title;
                                 galleryImages.Add(Mapper.Map <GalleryImage>(galleryImageViewModel));
                             }
                             num++;
                         }
                         else
                         {
                             num++;
                         }
                     }
                 }
             }
             Post post1 = Mapper.Map <PostViewModel, Post>(post);
             post1.GalleryImages = galleryImages;
             this._postService.Create(post1);
             return(base.RedirectToAction("PostManagement"));
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         ExtentionUtils.Log(string.Concat("Post.Create: ", exception.Message));
         base.ModelState.AddModelError("", exception.Message);
     }
     return(base.View(post));
 }
Пример #6
0
        public ActionResult Edit(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 objGenericControl = _genericControlService.GetById(model.Id);

                    List <MenuLink> lstMenuLink = new List <MenuLink>();
                    List <int>      lstMenuId   = new List <int>();

                    string menuLink = this.Request["MenuLink"];
                    if (!string.IsNullOrEmpty(menuLink))
                    {
                        foreach (var item in menuLink.Split(new char[] { ',' }).ToList <string>())
                        {
                            int menuId = int.Parse(item);
                            lstMenuId.Add(menuId);

                            lstMenuLink.Add(_menuLinkService.GetById(menuId, isCache: false));
                        }

                        if (lstMenuId.IsAny())
                        {
                            (from x in objGenericControl.MenuLinks
                             where !lstMenuId.Contains(x.Id)
                             select x).ToList <MenuLink>()
                            .ForEach((MenuLink m) =>
                                     objGenericControl.MenuLinks.Remove(m)
                                     );
                        }
                    }
                    objGenericControl.MenuLinks = lstMenuLink;

                    GenericControl modelMap = Mapper.Map <GenericControlViewModel, GenericControl>(model);
                    this._genericControlService.Update(objGenericControl);


                    //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.UpdateSuccess, 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);
        }
Пример #7
0
        public ActionResult Edit(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 (!_postService.FindBy((Post x) => x.ProductCode.Equals(model.ProductCode) && x.Id != model.Id, true).IsAny <Post>())
                {
                    Post byId = this._postService.GetById(model.Id, isCache: false);

                    string titleNonAccent           = model.Title.NonAccent();
                    IEnumerable <MenuLink> bySeoUrl = this._menuLinkService.GetListSeoUrl(titleNonAccent, isCache: false);

                    model.SeoUrl = model.Title.NonAccent();
                    if (bySeoUrl.Any <MenuLink>((MenuLink x) => x.Id != model.Id))
                    {
                        PostViewModel postViewModel = model;
                        postViewModel.SeoUrl = string.Concat(postViewModel.SeoUrl, "-", bySeoUrl.Count <MenuLink>());
                    }
                    //string str1 = titleNonAccent;
                    //if (str1.Length > 250)
                    //{
                    //    str1 = Utils.Utils.SplitWords(250, str1);
                    //}

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

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

                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, false);
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName2, ImageSize.WithMediumSize, ImageSize.HeightMediumSize, false);
                        this._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 menuLink = menuLinkService.GetById(menuId.Value, isCache: false);
                        model.VirtualCatUrl     = menuLink.VirtualSeoUrl;
                        model.VirtualCategoryId = menuLink.VirtualId;
                    }

                    //GalleryImage
                    HttpFileCollectionBase files            = base.Request.Files;
                    List <GalleryImage>    lstGalleryImages = new List <GalleryImage>();
                    if (files.Count > 0)
                    {
                        int count = files.Count - 1;
                        int num   = 0;

                        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 fileName1 = string.Format("{0}-{1}.jpg", titleNonAccent, Guid.NewGuid());
                                        string fileName2 = string.Format("{0}-{1}.jpg", titleNonAccent, Guid.NewGuid());

                                        this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName1, ImageSize.WithBigSize, ImageSize.WithBigSize, false);
                                        this._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));

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

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

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

                    byId.AttributeValues = lstAttributeValues;

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

                    //Update GalleryImage
                    if (lstAttributeValues.IsAny <AttributeValue>())
                    {
                        foreach (AttributeValue attributeValue in lstAttributeValues)
                        {
                            GalleryImage nullable = this._galleryService.Get((GalleryImage x) => x.AttributeValueId == attributeValue.Id && x.PostId == model.Id, false);
                            if (nullable == null)
                            {
                                continue;
                            }
                            HttpRequestBase request = base.Request;
                            i = attributeValue.Id;
                            double num2 = double.Parse(request[i.ToString()]);
                            nullable.Price = new double?(num2);
                            this._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);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, 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)
            {
                base.ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(string.Concat("Post.Edit: ", ex.Message));

                return(base.View(model));
            }

            return(action);
        }
Пример #8
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             str      = model.Title.NonAccent();
                    IEnumerable <Post> bySeoUrl = this._postService.GetBySeoUrl(str);
                    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 str1 = str;
                    if (str1.Length > 250)
                    {
                        str1 = AdminHelper.SplitWords(250, str1);
                    }
                    string str2 = string.Format("{0:ddMMyyyy}", DateTime.UtcNow);
                    if (model.Image != null && model.Image.ContentLength > 0)
                    {
                        string str3 = string.Concat(str1, ".jpg");
                        string str4 = string.Format("{0}-{1}.jpg", str1, Guid.NewGuid());
                        string str5 = string.Format("{0}-{1}.jpg", str1, Guid.NewGuid());
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, str2), str3, new int?(ImageSize.WithBigSize), new int?(ImageSize.HeightBigSize), false);
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, str2), str4, new int?(ImageSize.WithMediumSize), new int?(ImageSize.HeightMediumSize), false);
                        this._imagePlugin.CropAndResizeImage(model.Image, string.Format("{0}{1}/", Contains.PostFolder, str2), str5, new int?(ImageSize.WithSmallSize), new int?(ImageSize.HeightSmallSize), false);
                        model.ImageBigSize    = string.Format("{0}{1}/{2}", Contains.PostFolder, str2, str3);
                        model.ImageMediumSize = string.Format("{0}{1}/{2}", Contains.PostFolder, str2, str4);
                        model.ImageSmallSize  = string.Format("{0}{1}/{2}", Contains.PostFolder, str2, str5);
                    }
                    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;
                    }
                    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    = str;
                        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 str9  = string.Format("{0}-{1}.jpg", str6, Guid.NewGuid());
                                        string str10 = string.Format("{0}-{1}.jpg", str6, Guid.NewGuid());
                                        this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, str2), str9, new int?(ImageSize.WithBigSize), new int?(ImageSize.HeightBigSize), false);
                                        this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, str2), str10, new int?(ImageSize.WithThumbnailSize), new int?(ImageSize.HeightThumbnailSize), false);
                                        galleryImageViewModel.ImageThumbnail = string.Format("{0}{1}/{2}", Contains.PostFolder, str2, str10);
                                        galleryImageViewModel.ImagePath      = string.Format("{0}{1}/{2}", Contains.PostFolder, str2, str9);
                                        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++;
                                }
                            }
                        }
                    }
                    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 exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("Post.Create: ", exception.Message));
                base.ModelState.AddModelError("", exception.Message);
                return(base.View(model));
            }
            return(action);
        }
Пример #9
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);
        }
Пример #10
0
        public ActionResult Edit(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
                {
                    MenuLink byId = this._menuLinkService.GetById(model.Id);
                    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);
                    }
                    int?parentId = model.ParentId;
                    if (!parentId.HasValue)
                    {
                        parentId            = null;
                        model.ParentId      = parentId;
                        model.VirtualId     = byId.CurrentVirtualId;
                        model.VirtualSeoUrl = null;
                    }
                    else
                    {
                        IMenuLinkService menuLinkService = this._menuLinkService;
                        parentId = model.ParentId;
                        MenuLink byId1 = menuLinkService.GetById(parentId.Value);
                        model.VirtualId     = string.Format("{0}/{1}", byId1.VirtualId, byId.CurrentVirtualId);
                        model.VirtualSeoUrl = string.Format("{0}/{1}", byId1.SeoUrl, model.SeoUrl);
                    }

                    MenuLink modelMap = Mapper.Map(model, byId);
                    this._menuLinkService.Update(byId);

                    //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.UpdateSuccess, 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 ex)
            {
                base.ModelState.AddModelError("", ex.Message);
                ExtentionUtils.Log(string.Concat("MailSetting.Create: ", ex.Message));

                return(base.View(model));
            }

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