public JsonResult SaveSchedule()
        {
            var    data          = Request.GetArrayList("data");
            int    week          = Request.GetInt("week");
            long   MealTimesCode = Request.GetInt("MealTimesCode");
            string MealTimesName = Request.GetString("MealTimesName");

            using (var context = flexibleContext.db.UseTransaction(true))
            {
                var mealScheduleDal = flexibleContext.GetService <MealScheduleDal>();
                mealScheduleDal.Db.Sql("delete from dc_mealschedule where DayOfWeek = @0 and MealTimesCode = @1", week,
                                       MealTimesCode).Execute();
                foreach (var o in data)
                {
                    MealSchedule model = new MealSchedule();
                    model.MealTimesCode = MealTimesCode;
                    model.MealTimesName = MealTimesName;
                    model.DayOfWeek     = week;
                    model.MealMenuID    = Convert.ToInt32(o["ItemID"].ToString().Split('_')[1]);
                    mealScheduleDal.Insert(model);
                }

                context.Commit();
            }

            var result = new { };

            return(Json(result));
        }
Exemple #2
0
        public ActionResult ConfigureMeal(MealSchedule mealSchedule)
        {
            mealSchedule.MealDay = mealSchedule.MealDay == 7 ? 0 : mealSchedule.MealDay;
            var result = _mealLogic.ConfigureMeal(mealSchedule);

            return(Json(result));
        }
        public static Attachment GetDailyMenuCard(MealSchedule mealSchedule)
        {
            if (mealSchedule is null)
            {
                throw new ArgumentNullException(nameof(mealSchedule));
            }

            StringBuilder content = new StringBuilder();

            content.Append("{");

            content.Append("\"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",");
            content.Append("\"type\": \"AdaptiveCard\",");
            content.Append("\"version\": \"1.0\",");

            content.Append("\"body\": [");

            content.Append("{");
            content.Append("\"type\": \"TextBlock\",");
            content.AppendFormat("\"text\": \"{0}\",", mealSchedule.Day);
            content.Append("\"weight\": \"Bolder\"");
            content.Append("},");

            content.Append("{");

            content.Append("\"type\": \"FactSet\",");
            content.Append("\"facts\": [");

            content.Append("{");
            content.AppendFormat("\"title\": \"{0}\",", ipnbarbot.Application.Constants.MealTypeNames.Soup);
            content.AppendFormat("\"value\": \"{0}\"", mealSchedule.SoupMeal.Name);
            content.Append("},");

            content.Append("{");
            content.AppendFormat("\"title\": \"{0}\",", ipnbarbot.Application.Constants.MealTypeNames.MainDish);
            content.AppendFormat("\"value\": \"{0}\"", mealSchedule.MainDishMeal.Name);
            content.Append("},");

            content.Append("{");
            content.AppendFormat("\"title\": \"{0}\",", ipnbarbot.Application.Constants.MealTypeNames.VeganDish);
            content.AppendFormat("\"value\": \"{0}\"", mealSchedule.VeganDishMeal.Name);
            content.Append("}");

            content.Append("]");

            content.Append("}");

            content.Append("]");

            content.Append("}");

            return(new Attachment()
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content = JsonConvert.DeserializeObject(content.ToString()),
            });
        }
Exemple #4
0
 public void DataMaintainerService_EditMealSchedule_EditMealScheduleInDatabase()
 {
     dataHandler.AddMealschedule(mS1);
     controller.DataMaintainerService.EditMealSchedule(mS1.Id, mS2.Topic, mS2.Participants, mS2.Location, mS2.StartDate, mS2.EndDate, mS2.LastEditUserId);
     testMSchedule = dataHandler.FindMealScheduleById(mS1.Id);
     Assert.AreEqual(mS2.Topic, testMSchedule.Topic);
     Assert.AreEqual(mS2.Participants, testMSchedule.Participants);
     Assert.AreEqual(mS2.Location, testMSchedule.Location);
     Assert.AreEqual(mS2.StartDate, testMSchedule.StartDate);
     Assert.AreEqual(mS2.EndDate, testMSchedule.EndDate);
 }
Exemple #5
0
        //-----------------------------------DataMaintainerService-----------------------------------------

        private Boolean CompareMealSchedule(MealSchedule mealSchedule1, MealSchedule mealSchedule2)
        {
            Boolean isSame = (mealSchedule1.Id.Equals(mealSchedule2.Id)) &&
                             (mealSchedule1.Topic.Equals(mealSchedule2.Topic)) &&
                             (mealSchedule1.Participants.Equals(mealSchedule2.Participants)) &&
                             (mealSchedule1.Location.Equals(mealSchedule2.Location)) &&
                             (mealSchedule1.StartDate.Equals(mealSchedule2.StartDate)) &&
                             (mealSchedule1.EndDate.Equals(mealSchedule2.EndDate)) &&
                             (mealSchedule1.LastEditUserId.Equals(mealSchedule2.LastEditUserId)) ? true : false;

            return(isSame);
        }
Exemple #6
0
        private bool _ConfigureMeal(MealSchedule mealSchedule)
        {
            var sql        = "INSERT INTO `order_center`.`meal_schedule` (`id`,`meal_day`,`meal_id`,`date_created`,`last_updated`,`meal_type`) VALUES(NULL, @meal_day,@meal_id,now(),now(),@meal_type)";
            var parameters = new Parameter[]
            {
                new Parameter("@meal_day", mealSchedule.MealDay),
                new Parameter("@meal_id", mealSchedule.MealId),
                new Parameter("@meal_type", mealSchedule.MealType)
            };

            return(DBHelper.ExecuteNonQuery(sql, parameters));
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Controller"] != null)
            {
                controller = (Controller)Session["Controller"];

                //Reject access if no permission
                if (!controller.CurrentUser.Role.ToString().Contains("DM"))
                {
                    Response.Redirect("~/");
                }
            }
            else
            {
                Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                Response.Redirect("~/");
            }

            if (IsPostBack)
            {
                // Retrieve the ID from the view state
                currentId = (string)ViewState[IdKey];
            }
            else
            {
                //Retrieve the ID from the query string
                string id = Request.QueryString[IdKey];
                if (id != null && id != "")
                {
                    // Edit Mode
                    ModeLabel.Text = "Edit";

                    // Save the ID for later
                    ViewState[IdKey] = id;
                    currentId        = id;
                    // Get current data
                    MealSchedule ms = controller.DataMaintainerService.FindMealScheduleById(currentId);
                    if (ms != null)
                    {
                        TopicTextBox.Text        = ms.Topic;
                        ParticipantsTextBox.Text = ms.Participants;
                        LocationTextBox.Text     = ms.Location;
                        StartDateTextBox.Text    = ms.StartDate;
                        EndDateTextBox.Text      = ms.EndDate;
                    }
                    else
                    {
                        Response.Redirect("~/");
                    }
                }
            }
        }
        private async Task <string> GetMenuFor(DateTime date)
        {
            string response = null;

            MealSchedule menu = await this._mealSchedulesApp.GetForDate(date);

            if (menu is null)
            {
                throw new Exceptions.DefaultBotException("MenuNotFoundForDate");
            }
            else
            {
                response = ipnbarbot.Cards.CardsExtensions.GetDailyMenuCardAsString(menu);
            }

            return(response);
        }
        public static string GetDailyMenuCardAsString(MealSchedule mealSchedule)
        {
            if (mealSchedule is null)
            {
                throw new ArgumentNullException(nameof(mealSchedule));
            }

            StringBuilder result = new StringBuilder();

            result.Append(string.Format("**{0}**", mealSchedule.Day));
            result.Append(" \n ");
            result.Append(string.Format("* **{0}**: {1}", ipnbarbot.Application.Constants.MealTypeNames.Soup, mealSchedule.SoupMeal.Name));
            result.Append(" \n ");
            result.Append(string.Format("* **{0}**: {1}", ipnbarbot.Application.Constants.MealTypeNames.MainDish, mealSchedule.MainDishMeal.Name));
            result.Append(" \n ");
            result.Append(string.Format("* **{0}**: {1}", ipnbarbot.Application.Constants.MealTypeNames.VeganDish, mealSchedule.VeganDishMeal.Name));

            return(result.ToString());
        }
Exemple #10
0
        public bool ConfigureMeal(MealSchedule mealSchedule)
        {
            if (mealSchedule.MealId < 1)
            {
                throw new Exception("请输入有效的菜品!");
            }

            if (mealSchedule.MealDay < 0 || mealSchedule.MealDay > 6)
            {
                throw new Exception("请输入星期一至星期天的一天!");
            }

            if (mealSchedule.MealType < 1 || mealSchedule.MealType > 3)
            {
                throw new Exception("请输入早中晚三餐!");
            }

            return(_ConfigureMeal(mealSchedule));
        }
Exemple #11
0
 public void DataMaintainerService_AddMealSchedule_AddANewMealScheduleDataIntoDatabase()
 {
     controller.DataMaintainerService.AddMealSchedule(mS1.Topic, mS1.Participants, mS1.Location, mS1.StartDate, mS1.EndDate, mS1.LastEditUserId);
     testMSchedule = dataHandler.FindMealScheduleById(mS1.Id);
     Assert.IsTrue(CompareMealSchedule(mS1, testMSchedule));
 }