public IActionResult CreateOrEdit(CreateOrEditViewModel createOrEdit) { if (this.ModelState.IsValid) { Variable variable = new CreateOrEditViewModelMapper(this).Map(createOrEdit); if (createOrEdit.Id == null) this.Storage.GetRepository<IVariableRepository>().Create(variable); else this.Storage.GetRepository<IVariableRepository>().Edit(variable); this.Storage.Save(); return this.RedirectToAction("Index", "Configurations"); } return this.CreateRedirectToSelfResult(); }
public Variable Map(CreateOrEditViewModel createOrEdit) { Variable variable = new Variable(); if (createOrEdit.Id != null) { variable = this.handler.Storage.GetRepository <IVariableRepository>().WithKey((int)createOrEdit.Id); } else { variable.SectionId = createOrEdit.SectionId; } variable.Code = createOrEdit.Code; variable.Name = createOrEdit.Name; variable.Value = createOrEdit.Value; variable.Position = createOrEdit.Position; return(variable); }