コード例 #1
0
        public ActionResult Create()
        {
            var model = new GenericControlViewModel
            {
                OrderDisplay = 0,
                Status       = 1
            };

            //Add locales to model
            AddLocales(_languageService, model.Locales);

            return(base.View(model));
        }
コード例 #2
0
        public ActionResult Edit(int Id)
        {
            GenericControlViewModel modelMap = Mapper.Map <GenericControl, GenericControlViewModel>(this._genericControlService.GetById(Id));

            //Add Locales to model
            AddLocales(_languageService, modelMap.Locales, (locale, languageId) =>
            {
                locale.Id          = modelMap.Id;
                locale.LocalesId   = modelMap.Id;
                locale.Name        = modelMap.GetLocalized(x => x.Name, Id, languageId, false, false);
                locale.Description = modelMap.GetLocalized(x => x.Description, Id, languageId, false, false);
            });

            return(base.View(modelMap));
        }
コード例 #3
0
        public ActionResult Create(GenericControlViewModel model, string ReturnUrl)
        {
            ActionResult action;

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

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

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

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

                var modelMap = Mapper.Map <GenericControlViewModel, GenericControl>(model);
                _gCService.Create(modelMap);

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

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.GenericControl)));
                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("GenericControl.Create: ", ex.Message));

                return(View(model));
            }

            return(action);
        }
コード例 #5
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);
        }
コード例 #6
0
        public ActionResult Edit(GenericControlViewModel 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 objGenericControl = _gCService.GetById(model.Id);

                var menuLinks = new List <MenuLink>();
                var menuIds   = new List <int>();

                var menuLink = Request["MenuLink"];
                if (!string.IsNullOrEmpty(menuLink))
                {
                    foreach (var item in menuLink.Split(',').ToList())
                    {
                        var menuId = int.Parse(item);
                        menuIds.Add(menuId);

                        menuLinks.Add(_menuLinkService.GetMenu(menuId, false));
                    }

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

                var modelMap = Mapper.Map <GenericControlViewModel, GenericControl>(model);
                _gCService.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);
                }

                Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.GenericControl)));
                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("GenericControl.Create: ", ex.Message));

                return(View(model));
            }

            return(action);
        }