Example #1
0
        public ActionResult Edit()
        {
            int id;
            StringResourceModel model = new StringResourceModel();

            if (!int.TryParse(Request.QueryString["id"], out id))
            {
                model.CultureCodeList = new MultiSelectList(_resourceService.FetchCultureList());
                return(View(model));
            }
            var stringResource = _resourceService.GetResourceById(id);

            if (stringResource == null)
            {
                ModelState.AddModelError(string.Empty, this._resourceManager.GetString("StringResource_NotExists"));
            }
            else
            {
                model = base.Map <StringResourceModel>(stringResource);
                model.CultureCodeList = new MultiSelectList(_resourceService.FetchCultureList());
            }
            return(View(model));
        }
Example #2
0
        public ActionResult Edit(StringResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                model.CultureCodeList = new MultiSelectList(_resourceService.FetchCultureList());
                return(View(model));
            }
            try
            {
                if (model.Id > 0)
                {
                    StringResource tempStringResource = _resourceService
                                                        .GetResourceByNameAndCulture(model.CultureCode, model.Name);

                    if (tempStringResource != null && tempStringResource.Id != model.Id)
                    {
                        ModelState.AddModelError("Name",
                                                 string.Format(this._resourceManager.GetString("StringResource_Exists"), model.Name));
                    }
                    else
                    {
                        _resourceService.Update(this.Map <StringResource>(model));
                        _resourceManager.ClearCache();
                        TempData["ResultType"]    = MessageType.Success;
                        TempData["ResultMessage"] = string.Format(this._resourceManager.GetString("StringResources_SaveSuccess"),
                                                                  model.Name, model.CultureCode);
                        TempData["ResultModel"] = model;
                        return(RedirectToAction("Result", "Shared"));
                    }
                }
                else
                {
                    if (_resourceService
                        .GetResourceByNameAndCulture(model.CultureCode, model.Name) != null)
                    {
                        ModelState.AddModelError("Name",
                                                 string.Format(this._resourceManager.GetString("StringResource_Exists"),
                                                               model.Name, model.CultureCode));
                    }
                    else
                    {
                        _resourceService.Insert(Map <StringResource>(model));
                        _resourceManager.ClearCache();
                        TempData["ResultType"]    = MessageType.Success;
                        TempData["ResultMessage"] = string.Format(this._resourceManager.GetString("StringResources_SaveSuccess"),
                                                                  model.Name, model.CultureCode);
                        TempData["ResultModel"] = model;
                        return(RedirectToAction("Result", "Shared"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }
            finally
            {
                model.CultureCodeList = new MultiSelectList(_resourceService.FetchCultureList());
            }
            return(View(model));
        }