コード例 #1
0
        /// <summary>
        /// Adds an entry.
        /// </summary>
        /// <returns>View Result or Redirect to Home if successful</returns>
        /// <param name="baseModel">Model to add.</param>
        /// <param name="baseInterface">Interface to use to add with.</param>
        /// <typeparam name="T">The type of the Model.</typeparam>
        public IActionResult AddEntry <T>(T baseModel, IBaseInterface <T> baseInterface) where T : BaseModel
        {
            if (IsEmptyModel(baseModel))
            {
                // Haven't filled in the form yet
                return(View(baseModel));
            }

            if (ModelState.IsValid)
            {
                // Add the Company
                if (baseInterface.AddEntry(baseModel))
                {
                    // Add was successful
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    // Error with saving record
                    ModelState.AddModelError("Save Error", "Error saving record, please try again");
                }
            }

            // Display any errors on screen
            return(View(baseModel));
        }