public ActionResult SetDish(Set_Dish dish, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Temp/"), fileName); file.SaveAs(path); FileStream fs = new FileStream(path, FileMode.Open); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); dish.Example = new byte[buffer.Length]; dish.Example = buffer; fs.Close(); } else { dish.Example = new byte[1]; dish.Example[0] = 0; } bis_log.SetDish(dish); foreach (var filepath in System.IO.Directory.GetFiles(Server.MapPath("~") + "/Content/Temp")) { System.IO.File.Delete(filepath); } return(RedirectToAction("Mainpage")); }
public Set_Dish GetSingleDish(int id) { string sqlexpression = "dish_get_single"; Set_Dish dish = new Set_Dish(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlexpression, connection); // указываем, что команда представляет хранимую процедуру command.CommandType = System.Data.CommandType.StoredProcedure; var reader = command.ExecuteReader(); while (reader.Read()) { dish.Id = reader.GetInt32(0); dish.Dish = reader.GetString(1); dish.BookId = reader.GetInt32(2); dish.TypeId = reader.GetInt32(3); dish.Time = reader.GetInt32(4); dish.Temperature = reader.GetInt32(5); dish.Example = (byte[])reader.GetValue(6); dish.About = reader.GetString(7); dish.HowToCraft = reader.GetString(8); } reader.Close(); } return(dish); }
public void UpdateDish(Set_Dish dish) { dal.UpdateDish(dish); }
public void SetDish(Set_Dish dish) { dal.SetDishes(dish); }
public ActionResult SetDish() { var dish = new Set_Dish(); return(View(dish)); }
public void UpdateDish(Set_Dish dish) { string sqlexpression = "dish_update"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlexpression, connection); command.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter IdParam = new SqlParameter { ParameterName = "@id", Value = dish.Id }; command.Parameters.Add(IdParam); SqlParameter DishNameParam = new SqlParameter { ParameterName = "@dish", Value = dish.Dish }; command.Parameters.Add(DishNameParam); SqlParameter BookIdParam = new SqlParameter { ParameterName = "@bookid", Value = dish.BookId }; command.Parameters.Add(BookIdParam); SqlParameter TypeIdParam = new SqlParameter { ParameterName = "@typeid", Value = dish.TypeId }; command.Parameters.Add(TypeIdParam); SqlParameter TimeParam = new SqlParameter { ParameterName = "@time", Value = dish.Time }; command.Parameters.Add(TimeParam); SqlParameter ExampleParam = new SqlParameter { ParameterName = "@example", Value = dish.Example }; command.Parameters.Add(ExampleParam); SqlParameter AboutParam = new SqlParameter { ParameterName = "@about", Value = dish.About }; command.Parameters.Add(AboutParam); SqlParameter HowToCraftParam = new SqlParameter { ParameterName = "@howtocraft", Value = dish.HowToCraft }; command.Parameters.Add(HowToCraftParam); try { command.ExecuteNonQuery(); } catch { } } }
public ActionResult EditDish(Set_Dish dish) { bis_log.UpdateDish(dish); return(RedirectToAction("GetDishes")); }
public ActionResult EditDish(int id) { Set_Dish dish = bis_log.GetSingleDish(id); return(View(dish)); }