Ejemplo n.º 1
0
        private async Task <object> InsertModel(ContinentRequestModel model, string synonyms)
        {
            object id       = null;
            bool   inserted = false;

            if (!string.IsNullOrWhiteSpace(synonyms) && synonyms != "[]")
            {
                try
                {
                    var synonymsArray = JsonConvert.DeserializeObject <ContinentSynonymRequestModel[]>(synonyms);
                    var addedSynonyms = synonymsArray.Where(s => s.Status == UpdateStatus.Added).ToArray();
                    id = await this.service.InsertAsync(model, addedSynonyms);

                    inserted = true;
                }
                catch (Exception e)
                {
                    this.logger?.Log(e, string.Empty);
                    inserted = false;
                }
            }

            if (!inserted)
            {
                id = await this.service.InsertAsync(model);
            }

            return(id);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = nameof(ContinentRequestModel.Id) + "," + nameof(ContinentRequestModel.Name) + "," + nameof(ContinentRequestModel.AbbreviatedName))] ContinentRequestModel model, string synonyms, bool exit = false, bool createNew = false, bool cancel = false)
        {
            string returnUrl = this.Request[ContextKeys.ReturnUrl];

            if (cancel)
            {
                if (!string.IsNullOrWhiteSpace(returnUrl))
                {
                    return(this.Redirect(returnUrl));
                }
                else
                {
                    return(this.RedirectToAction(IndexActionName));
                }
            }

            try
            {
                if (this.ModelState.IsValid)
                {
                    await this.service.UpdateAsync(model);

                    await this.UpdateSynonymsFromJson(model.Id, synonyms);

                    if (createNew)
                    {
                        return(this.RedirectToAction(CreateActionName, routeValues: new { ReturnUrl = returnUrl }));
                    }

                    if (exit)
                    {
                        if (!string.IsNullOrWhiteSpace(returnUrl))
                        {
                            return(this.Redirect(returnUrl));
                        }
                        else
                        {
                            return(this.RedirectToAction(IndexActionName));
                        }
                    }

                    return(this.RedirectToAction(EditActionName, routeValues: new { id = model.Id, ReturnUrl = returnUrl }));
                }
                else
                {
                    this.AddErrors(Strings.InvalidDataErrorMessage);
                }
            }
            catch (Exception e)
            {
                this.logger?.Log(e, string.Empty);
                this.AddErrors(e.Message);
            }

            var viewModel = new ContinentPageViewModel
            {
                Model     = this.mapper.Map <ContinentViewModel>(model),
                PageTitle = Strings.EditPageTitle,
                ReturnUrl = returnUrl
            };

            this.ViewData[ContextKeys.AreaName]       = AreaName;
            this.ViewData[ContextKeys.ControllerName] = ControllerName;
            this.ViewData[ContextKeys.ActionName]     = EditActionName;
            this.ViewData[ContextKeys.BackActionName] = IndexActionName;
            return(this.View(EditActionName, viewModel));
        }