void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { // TODO: Add your action filter's tasks here // Log Action Filter call //using (MusicStoreEntities storeDb = new MusicStoreEntities()) //{ ActionLog log = new ActionLog() { Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = string.Concat(filterContext.ActionDescriptor.ActionName, " (Logged By: Custom Action Filter)"), IP1 = filterContext.HttpContext.Request.UserHostAddress, DateTime = filterContext.HttpContext.Timestamp }; //TODO: save to DB using connection var rdb = new RestaurantDBConnection(); var conn = rdb.Connection(); SqlCommand com = new SqlCommand("InsertActionLog", conn) { CommandType = CommandType.StoredProcedure }; com.Parameters.Add(new SqlParameter("@Controller", SqlDbType.VarChar)).Value = log.Controller; com.Parameters.Add(new SqlParameter("@Action", SqlDbType.VarChar)).Value = log.Action; com.Parameters.Add(new SqlParameter("@IP", SqlDbType.VarChar)).Value = log.IP1; com.Parameters.Add(new SqlParameter("@DateTime", SqlDbType.DateTime)).Value = log.DateTime; conn.Open(); com.ExecuteNonQuery(); conn.Close(); OnActionExecuting(filterContext); //} }
public List <Drink> GetAllDrinks() { //TODO: Clean this up. //TODO: Unit Test var rdb = new RestaurantDBConnection(); var conn = rdb.Connection(); var drinkList = new List <Drink>(); SqlCommand com = new SqlCommand("GetAllDrinks", conn) { CommandType = CommandType.StoredProcedure }; SqlDataAdapter da = new SqlDataAdapter(com); DataTable dt = new DataTable(); conn.Open(); da.Fill(dt); conn.Close(); drinkList = (from DataRow dr in dt.Rows select new Drink() { Id = Convert.ToInt32(dr["DrinkId"]), Name = Convert.ToString(dr["Name"]), Ice = Convert.ToBoolean(dr["Ice"]) }).ToList(); return(drinkList); }
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { ActionLog log = new ActionLog() { Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = filterContext.ActionDescriptor.ActionName + " (Logged By: MyNewCustomActionFilter)", IP1 = filterContext.HttpContext.Request.UserHostAddress, DateTime = filterContext.HttpContext.Timestamp }; var rdb = new RestaurantDBConnection(); var conn = rdb.Connection(); SqlCommand com = new SqlCommand("InsertActionLog", conn) { CommandType = CommandType.StoredProcedure }; com.Parameters.Add(new SqlParameter("@Controller", SqlDbType.VarChar)).Value = log.Controller; com.Parameters.Add(new SqlParameter("@Action", SqlDbType.VarChar)).Value = log.Action; com.Parameters.Add(new SqlParameter("@IP", SqlDbType.VarChar)).Value = log.IP1; com.Parameters.Add(new SqlParameter("@DateTime", SqlDbType.DateTime)).Value = log.DateTime; conn.Open(); com.ExecuteNonQuery(); conn.Close(); this.OnActionExecuting(filterContext); }