public virtual InjuryModel Get(int id)
        {
            InjuryModel Injury = null;

            using (SqlConnection connection = new SqlConnection(conString))
            {
                using (SqlCommand command = new SqlCommand("Book_Get", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ID", id);
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            Injury             = new InjuryModel();
                            Injury.ID          = (int)reader["ID"];
                            Injury.Name        = reader["BTitle"].ToString();
                            Injury.InjuryCause = reader["BAuthor"].ToString();
                            Injury.Summary     = reader["BSummary"].ToString();
                            Injury.Pain        = (int)reader["BRating"];
                            Injury.Length      = (int)reader["BLength"];
                            Injury.PostedBy    = reader["PostedBy"].ToString();
                        }
                    }
                }
            }
            return(Injury);
        }
        public virtual async Task <List <InjuryModel> > GetList()
        {
            List <InjuryModel> InjuryList = new List <InjuryModel>();

            using (SqlConnection connection = new SqlConnection(conString))
            {
                using (SqlCommand command = new SqlCommand("Book_GetList", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    await connection.OpenAsync();

                    using (SqlDataReader reader = await command.ExecuteReaderAsync())
                    {
                        while (reader.Read())
                        {
                            InjuryModel Injury = new InjuryModel();
                            Injury.ID          = (int)reader["ID"];
                            Injury.Name        = reader["BTitle"].ToString();
                            Injury.InjuryCause = reader["BAuthor"].ToString();
                            Injury.Summary     = reader["BSummary"].ToString();
                            Injury.Pain        = (int)reader["BRating"];
                            Injury.Length      = (int)reader["BLength"];
                            Injury.PostedBy    = reader["PostedBy"].ToString();
                            InjuryList.Add(Injury);
                        }
                    }
                }
            }
            return(InjuryList);
        }
示例#3
0
 public IActionResult PostInjury(InjuryModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     return(Create(model));
 }
示例#4
0
        public IActionResult PostInjury()
        {
            InjuryModel model = new InjuryModel();

            model.Date     = DateTime.Now;
            model.PostedBy = _UserManager.GetUserName(User);
            return(View(model));
        }
 public virtual void Save(InjuryModel Injury)
 {
     using (SqlConnection connection = new SqlConnection(conString))
     {
         using (SqlCommand command = new SqlCommand("Book_InsertUpdate", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             command.Parameters.AddWithValue("@ID", Injury.ID);
             command.Parameters.AddWithValue("@BTitle", Injury.Name);
             command.Parameters.AddWithValue("@BAuthor", Injury.InjuryCause);
             command.Parameters.AddWithValue("@BSummary", Injury.Summary);
             command.Parameters.AddWithValue("@BRating", Injury.Pain);
             command.Parameters.AddWithValue("@BLength", Injury.Length);
             command.Parameters.AddWithValue("@PostedBy", Injury.PostedBy);
             int rows = command.ExecuteNonQuery();
             if (rows <= 0)
             {
                 Console.Error.WriteLine("Didn't Work");
             }
         }
     }
 }
示例#6
0
 public override void Save(InjuryModel Injury)
 {
     base.Save(Injury);
     _Cache.Remove(_CacheListKey);
 }
示例#7
0
        public IActionResult View(int id)
        {
            InjuryModel a = _InjuryRepo.Get(id);

            return(View(a));
        }
示例#8
0
        public IActionResult Edit(int id)
        {
            InjuryModel Injury = _InjuryRepo.Get(id);

            return(View(Injury));
        }
示例#9
0
 protected IActionResult Create(InjuryModel model)
 {
     _InjuryRepo.Save(model);
     return(RedirectToAction("Index"));
 }