Beispiel #1
0
        public IActionResult Store(MealDate mealDate)
        {
            // Validate form
            if (ModelState.IsValid)
            {
                // Get meal
                Meal meal = mealDate.Meal;
                // Combine date and time
                meal.DateTime = new DateTime(meal.DateTime.Year, meal.DateTime.Month, meal.DateTime.Day, mealDate.Time.Hour, mealDate.Time.Minute, 0);
                // Set student cook
                Student student = studentRepository.GetStudent(GetUserId());
                meal.Cook = student;

                // Save to repo
                mealRepository.SaveMeal(meal);
            }
            else
            {
                // If form is not valid return from to user and pass meal date to fill in values
                return(View("Create", mealDate));
            }

            // Return user to main view and show success message
            TempData["success"] = "Maaltijd aangemaakt";
            return(RedirectToAction("List"));
        }
Beispiel #2
0
        // Transforms a list of meals into meal dates
        public static ICollection <MealDate> TransformMeals(IEnumerable <Meal> meals, Student student)
        {
            // Create model
            ICollection <MealDate> mealDates = new List <MealDate>();

            // Get all dates for coming 2 weeks -> loop through
            // Insert information regarding this meal in the mealdate model
            foreach (var d in DateTime.Now.GetDatesForComingTwoWeeks())
            {
                // Get meal for this date
                var meal = meals.FirstOrDefault(m => m.DateTime.Date == d.Date);
                // Store information
                var mealDate = new MealDate()
                {
                    Date            = d,
                    MonthString     = d.ToString("MMMM"),
                    DayOfWeekString = UppercaseFirst(d.ToString("dddd")),
                    Meal            = meal,
                    UserHasJoined   = CheckIfUserIsRegistered(meal, student),
                    UserIsCook      = CheckIfUserIsCook(meal, student),
                    MealIsFull      = meal?.Guests?.Count >= meal?.MaxGuests && false
                };
                // Add meal date to model
                mealDates.Add(mealDate);
            }

            // Return model
            return(mealDates);
        }
Beispiel #3
0
        public IActionResult Edit(MealDate mealDate)
        {
            // Check if user filled in form correctly
            if (!ModelState.IsValid)
            {
                // If not => return edit view again => send meal date to fill in values
                return(View(mealDate));
            }

            // Get meal
            Meal meal = mealRepository.GetMeal(mealDate.Meal.Id);
            // Get student
            Student student = studentRepository.GetStudent(GetUserId());

            // Check if meal can be edited by student
            DomainMethodResult result = meal.AllowedToEdit(student);

            // Meal cannot be edited by student -> add with error
            if (!result.WasSuccessful)
            {
                TempData["error"] = result.Message;
            }
            // Meal can be edited by student -> update meal -> add success message
            else
            {
                // Combine date and time
                mealDate.Meal.DateTime = new DateTime(mealDate.Meal.DateTime.Year, mealDate.Meal.DateTime.Month, mealDate.Meal.DateTime.Day, mealDate.Time.Hour, mealDate.Time.Minute, 0);
                // Update meal in database
                mealRepository.SaveMeal(mealDate.Meal);
                TempData["success"] = "Maaltijd succesvol bijgewerkt";
            }

            return(RedirectToAction("List"));
        }
 public bool SaveMealScheduleIsExist(MealDate meal)
 {
     try
     {
         bool isNameExists = false;
         Query = "SELECT*FROM MealSchedule WHERE EmpId='" + meal.EmpId + "' AND Date='" + meal.Date + "' AND ItemId='" + meal.ItemId + "'";
         Command.CommandText = Query;
         Command.Connection  = Connection;
         Connection.Open();
         Reader = Command.ExecuteReader();
         if (Reader.HasRows)
         {
             isNameExists = true;
         }
         return(isNameExists);
     }
     catch (Exception exception)
     {
         return(false);
     }
     finally
     {
         Connection.Close();
     }
 }
        public int SaveMealSchedule(MealDate meal)
        {
            try
            {
                Query = "INSERT INTO MealSchedule(EmpId, Date, ItemId, Status, Quantity) VALUES(@EmpId, @Date, @ItemId, @Status, @Quantity)";
                Command.CommandText = Query;
                Command.Connection  = Connection;
                Command.Parameters.Clear();

                Command.Parameters.Add("EmpId", SqlDbType.VarChar);
                Command.Parameters["EmpId"].Value = meal.EmpId;
                Command.Parameters.Add("Date", SqlDbType.Date);
                Command.Parameters["Date"].Value = meal.Date;
                Command.Parameters.Add("ItemId", SqlDbType.Int);
                Command.Parameters["ItemId"].Value = meal.ItemId;
                Command.Parameters.Add("Status", SqlDbType.VarChar);
                Command.Parameters["Status"].Value = meal.Status;
                Command.Parameters.Add("Quantity", SqlDbType.Int);
                Command.Parameters["Quantity"].Value = meal.Quantity;

                Connection.Open();
                int rowsAffected = Command.ExecuteNonQuery();
                return(rowsAffected);
            }
            catch (Exception exception)
            {
                return(0);
            }
            finally
            {
                Connection.Close();
            }
        }
 public int SaveMealSchedule(MealDate meal)
 {
     if (_mealSchedule.SaveMealScheduleIsExist(meal))
     {
         return(0);
     }
     return(_mealSchedule.SaveMealSchedule(meal));
 }
Beispiel #7
0
        // Transforms a single meal into meal date
        public static MealDate TransformIntoMealDate(Meal meal, Student student = null)
        {
            // Store information
            MealDate mealDate = new MealDate {
                Date            = meal.DateTime,
                Time            = meal.DateTime,
                MonthString     = meal.DateTime.ToString("MMMM"),
                DayOfWeekString = UppercaseFirst(meal.DateTime.ToString("dddd")),
                Meal            = meal,
                UserHasJoined   = CheckIfUserIsRegistered(meal, student),
                UserIsCook      = CheckIfUserIsCook(meal, student),
                MealIsFull      = meal?.Guests?.Count >= meal?.MaxGuests && false
            };

            return(mealDate);
        }
        public ActionResult GetLunchSchedule(SendMale sendMale)
        {
            //string checkTime = DateTime.Now.TimeOfDay.ToString();

            List <DateTime> dates      = new List <DateTime>();
            var             datesDispo = sendMale.DateCollection.Split(',');

            foreach (var date1 in datesDispo)
            {
                dates.Add(DateTime.ParseExact(date1, "dd/MM/yyyy", null));
            }

            MealDate meal = new MealDate();

            meal.EmpId    = Session["EmpId"].ToString();
            meal.ItemId   = 6;
            meal.Quantity = 1;
            meal.Status   = "Pending";
            int number = 0;

            foreach (var date2 in dates)
            {
                DateTime datea  = DateTime.Now;
                DateTime dateb  = date2;
                int      result = DateTime.Compare(datea, dateb);
                string   relationship;

                if (result < 0)
                {
                    meal.Date = date2.ToString();
                    number   += _mealSchedule.SaveMealSchedule(meal);
                }
            }
            string msg = number + " " + "Lunch Schedule Save";

            if (number != 0)
            {
                TempData["msg"] = msg;
            }
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #9
0
        public override string ToString()
        {
            string str = "";

            str += "&idserver=\"" + IDServer.ToString() + "\"";

            if (IDUser != -1)
            {
                str += "&iduser=\"" + IDUser.ToString() + "\"";
            }
            if (IDCategory != 0)
            {
                str += "&idcategory=\"" + IDCategory.ToString() + "\"";
            }
            if (IDMealUnit != 0)
            {
                str += "&idmealunit=\"" + IDServerMealUnit.ToString() + "\"";
            }
            if (Qty != 0)
            {
                str += "&qty=\"" + Qty.ToString() + "\"";
            }
            if (MealDate != null)
            {
                str += "&mealdate=\"" + MealDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"";
            }
            if (InsertDate != null)
            {
                str += "&insertdate=\"" + InsertDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"";
            }
            if (UpdateDate != null)
            {
                str += "&updatedate=\"" + UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"";
            }

            return(str.Substring(1));
        }
 public string GetHeaderMessage()
 {
     return("Maaltijd kiezen voor " +
            MealDate.ToString("dddd, dd MMMM yyyy", (new CultureInfo("nl-NL")).DateTimeFormat));
 }
Beispiel #11
0
 public static void AddDateStrings(MealDate mealDate)
 {
     mealDate.DayOfWeekString = UppercaseFirst(mealDate.Date.ToString("dddd"));
     mealDate.MonthString     = mealDate.Date.ToString("MMMM");
 }
Beispiel #12
0
 public IActionResult Create(MealDate mealDate) =>
 View(mealDate);