示例#1
0
        public PriceOfMeal GetLastPrice()
        {
            string sql = "SELECT TOP 1 * FROM [PriceOfMeal] ORDER BY Id DESC";

            PriceOfMeal priceToReturn = new PriceOfMeal();

            Command = new SqlCommand(sql, Connection);

            Connection.Open();
            Reader = Command.ExecuteReader();

            if (Reader.Read())
            {
                /*
                 * [Id]
                 * ,[PricePerMeal]
                 * ,[DateOfUpdate]
                 * ,[TimeOfUpdate]
                 * ,[UserId]
                 */
                priceToReturn.Id           = Convert.ToInt32(Reader["Id"].ToString());
                priceToReturn.PricePerMeal = Convert.ToInt32(Reader["PricePerMeal"].ToString());
                priceToReturn.DateOfUpdate = Reader["DateOfUpdate"].ToString();
                priceToReturn.TimeOfUpdate = Reader["TimeOfUpdate"].ToString();
                priceToReturn.UserId       = Convert.ToInt32(Reader["UserId"]);

                Connection.Close();

                return(priceToReturn);
            }

            return(null);
        }
示例#2
0
        public int SetPirce(PriceOfMeal priceOfMeal)
        {
            DateTime currentDate = BdTime.GetCurrentDate();

            string sql = "INSERT INTO [PriceOfMeal]" +
                         " (PricePerMeal,DateOfUpdate,TimeOfUpdate,UserId)" +
                         " VALUES(@pricePerMeal,@date,@time,@userId)";

            Command = new SqlCommand(sql, Connection);

            Command.Parameters.AddWithValue("@pricePerMeal", priceOfMeal.PricePerMeal);
            Command.Parameters.AddWithValue("@userId", priceOfMeal.UserId);

            Command.Parameters.AddWithValue("@date", currentDate.ToString("yyyy-MM-dd"));
            Command.Parameters.AddWithValue("@time", currentDate.ToString("HH:mm:ss"));

            Connection.Open();

            int rowEffected = Command.ExecuteNonQuery();

            Connection.Close();



            return(rowEffected);
        }
示例#3
0
        public string SetPirce(PriceOfMeal priceOfMeal)
        {
            PriceOfMealGateway priceOfMealGateway = new PriceOfMealGateway();

            if (priceOfMealGateway.SetPirce(priceOfMeal) > 0)
            {
                return("Price set successfully");
            }

            return("Price set failed");
        }
示例#4
0
        public ActionResult Index(int?pricepermeal)
        {
            int pricePermealValidate = Convert.ToInt32(pricepermeal);

            if (pricePermealValidate <= 0)
            {
                return(View());
            }
            PriceOfMealManager priceOfMealManager = new PriceOfMealManager();
            PriceOfMeal        priceOfMeal        = new PriceOfMeal();
            User currentUser = SetSession.GetCurrentUser();

            priceOfMeal.PricePerMeal = pricePermealValidate;
            priceOfMeal.UserId       = currentUser.Id;

            ViewBag.msg = priceOfMealManager.SetPirce(priceOfMeal);
            return(View());
        }