예제 #1
0
 protected virtual void UpdateLocales(WB_SimpleMenuItem item, WB_SimpleMenuItemModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(item,
                                                    x => x.Title,
                                                    localized.Title,
                                                    localized.LanguageId);
     }
 }
예제 #2
0
        public ActionResult Item(int menuId, int id = 0)
        {
            var model = new WB_SimpleMenuItemModel();

            if (id == 0)
            {
                var newItem = new WB_SimpleMenuItemModel
                {
                    MenuID = menuId
                };
                newItem.Locales = new List <WB_SimpleMenuItemLocalizedModel>();
                foreach (var lang in _languageService.GetAllLanguages())
                {
                    newItem.Locales.Add(new WB_SimpleMenuItemLocalizedModel
                    {
                        LanguageId = lang.Id,
                    });
                }
                model = newItem;
            }
            else
            {
                var item = _simpleMenuItemRepo.GetById(id);
                model.Id           = item.Id;
                model.MenuID       = item.MenuID;
                model.Title        = item.Title;
                model.Url          = item.Url;
                model.Order        = item.Order;
                model.IconUrlImage = item.IconUrlImage;
                model.Locales      = new List <WB_SimpleMenuItemLocalizedModel>();
                foreach (var lang in _languageService.GetAllLanguages())
                {
                    var title = item.GetLocalized(x => x.Title, lang.Id);
                    model.Locales.Add(new WB_SimpleMenuItemLocalizedModel
                    {
                        LanguageId = lang.Id,
                        Title      = title
                    });
                }
            }
            return(PartialView("~/Plugins/Worldbuy.SimpleMenu/Views/_CreateOrUpdate.Item.cshtml", model));
        }
예제 #3
0
        public ActionResult SaveItem(WB_SimpleMenuItemModel model)
        {
            bool   status   = false;
            string message  = "Error";
            string fileName = "";

            if (ModelState.IsValid)
            {
                try
                {
                    if (Request.Files != null && Request.Files.Count > 0)
                    {
                        HttpPostedFileBase file = Request.Files[0];
                        if (file != null && file.ContentLength > 0)
                        {
                            var folder     = "~/Content/Images/Worldbuy.SimpleMenu/Icons";
                            var folderPath = Server.MapPath(folder);
                            if (!System.IO.Directory.Exists(folderPath))
                            {
                                System.IO.Directory.CreateDirectory(folderPath);
                            }
                            fileName = folder + "/" + file.FileName;
                            string filePath = Server.MapPath(fileName);
                            file.SaveAs(filePath);
                        }
                    }

                    var entity = _simpleMenuItemRepo.GetById(model.Id) ?? new WB_SimpleMenuItem
                    {
                        Id           = 0,
                        MenuID       = model.MenuID,
                        Title        = model.Title,
                        Url          = model.Url,
                        Order        = model.Order,
                        IconUrlImage = fileName != "" ? Url.Content(fileName) : fileName
                    };
                    if (model.Id == 0)
                    {
                        _simpleMenuItemRepo.Insert(entity);
                    }
                    else
                    {
                        entity.Title = model.Title;
                        entity.Url   = model.Url;
                        entity.Order = model.Order;
                        _simpleMenuItemRepo.Update(entity);
                    }
                    UpdateLocales(entity, model);
                    if (entity.Id > 0)
                    {
                        status  = true;
                        message = "Success";
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    LogException(ex);
                }
            }


            return(Json(new { Status = status, Message = message }));
        }