public IActionResult Manage(Submodule submodule) { if (!ModelState.IsValid && submodule.Id > 0) { return(View(submodule)); } submodule.UpdatedDate = DateTime.Now; submodule.CreatedDate = submodule.Id > 0 ? submodule.CreatedDate : DateTime.Now; _context.Entry(submodule).State = Microsoft.EntityFrameworkCore.EntityState.Added; if (_context.SaveChanges() > 0) { TempData["SuccessAlert"] = String.Format("{0} is successfully saved.", submodule.Name); } else { TempData["ErrorAlert"] = String.Format("An error occured while saving {0}.", submodule.Name); } return(RedirectToAction("List")); }
public IActionResult Manage(SubmoduleParameter submoduleParameter) { switch (submoduleParameter.Type) { case ParameterValueType.Bool: if (!bool.TryParse(submoduleParameter.Value, out bool boolValue)) { ModelState.AddModelError("Value", string.Format("{0} is not a valid boolean value.", submoduleParameter.Value)); } break; case ParameterValueType.DateTime: if (!DateTime.TryParse(submoduleParameter.Value, out DateTime dateTimeValue)) { ModelState.AddModelError("Value", string.Format("{0} is not a valid datetime value.", submoduleParameter.Value)); } break; case ParameterValueType.Decimal: if (!decimal.TryParse(submoduleParameter.Value, out decimal decimalValue)) { ModelState.AddModelError("Value", string.Format("{0} is not a valid decimal value.", submoduleParameter.Value)); } break; case ParameterValueType.Integer: if (!int.TryParse(submoduleParameter.Value, out int integerValue)) { ModelState.AddModelError("Value", string.Format("{0} is not a valid integer value.", submoduleParameter.Value)); } break; default: ModelState.AddModelError("Error", "A valid value type required."); break; } if (!ModelState.IsValid) { ViewBag.ParameterValueTypes = ParameterValueType.GetAll(); return(View(submoduleParameter)); } var persistentSubmoduleParameter = submoduleParameter.Id > 0 ? _context.SubmoduleParameter.Find(submoduleParameter.Id) : new SubmoduleParameter(); persistentSubmoduleParameter.Name = submoduleParameter.Name; persistentSubmoduleParameter.Description = submoduleParameter.Description; persistentSubmoduleParameter.IsActive = submoduleParameter.IsActive; persistentSubmoduleParameter.Type = submoduleParameter.Type; persistentSubmoduleParameter.Value = submoduleParameter.Value; persistentSubmoduleParameter.UpdatedDate = DateTime.Now; persistentSubmoduleParameter.CreatedDate = submoduleParameter.Id > 0 ? submoduleParameter.CreatedDate : DateTime.Now; if (persistentSubmoduleParameter.Id == 0) { _context.Entry(submoduleParameter).State = Microsoft.EntityFrameworkCore.EntityState.Added; } if (_context.SaveChanges() > 0) { TempData["SuccessAlert"] = String.Format("{0} is successfully saved.", submoduleParameter.Name); } else { TempData["ErrorAlert"] = String.Format("An error occured while saving {0}.", submoduleParameter.Name); } return(RedirectToAction("List", new { submoduleId = submoduleParameter.SubmoduleId })); }