public ActionResult ModifySelfMeal(string mealId, string b, string l, string d) { SelfMealsModel smm = new SelfMealsModel(); //Breakfst if (b != "1") { smm.breakfast = "0"; } else { smm.breakfast = "1"; } //Lunch if (l != "1") { smm.lunch = "0"; } else { smm.lunch = "1"; } //Dinner if (d != "1") { smm.dinner = "0"; } else { smm.dinner = "1"; } //Other info smm.id = mealId; //Update meal smm.updateMeal(); if (smm.response == "500") { return(Json(new { msgtype = "e", msg = "Something went wrong! Try again..." })); } else { return(Json(new { msgtype = "s", msg = "Added successfully!" })); } }
private void getSelfMeals(string mid) { string response = ""; SelfMealsModel smm = new SelfMealsModel(); //Get self meal smm.memberId = mid; smm.date = getDate(); SelfMealsModel smm2 = new SelfMealsModel(); smm.getMealByMemberIdAndDate(); //Process result if (smm.response == "500") { response = "e"; ViewBag.SelfTotal = 0; } else { response = "s"; //Count meals int totalMeal = 0; string b = "No"; string l = "No"; string d = "No"; if (smm.breakfast == "1") { b = "Yes"; totalMeal++; } if (smm.lunch == "1") { l = "Yes"; totalMeal++; } if (smm.dinner == "1") { d = "Yes"; totalMeal++; } ViewBag.MealID = smm.id; ViewBag.SelfB = b; ViewBag.SelfL = l; ViewBag.SelfD = d; ViewBag.SelfTotal = totalMeal; } ViewBag.SelfResponse = response; }
public ActionResult cancelDinner(string m) { //Run auto meal scheduler Tasks task = new Tasks(); task.autoScheduler(); if (Session["user"] != null) { UserSessionModel session = (UserSessionModel)Session["user"]; if (session.acctype == "m") { SelfMealsModel smm = new SelfMealsModel(); smm.memberId = m; smm.date = getDate(); smm.cancelDinnerByMemberIdAndDate(); if (smm.response == "500") { return(Json(new { msgtype = "e", msg = "Something went wrong! Try again..." }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { msgtype = "s", msg = "Deleted successfully!" }, JsonRequestBehavior.AllowGet)); } } else { return(RedirectToAction("UserLogin", "User")); } } else { return(RedirectToAction("UserLogin", "User")); } }
private void processReport(string month, string year) { //Get all users string response = ""; UsersModel usm = new UsersModel(); List <UsersModel> usList = new List <UsersModel>(); //Get preferences PreferencesModel pm = new PreferencesModel(); pm.getPrefrences(); foreach (UsersModel user in usm.getAllUsers()) { usList.Add(user); } if (usm.response == "500") { response = "e"; } else { response = "s"; int totalMeals = 0; int totalMealCost = 0; int serviceCharge = 0; int totalCost = 0; string showing = ""; string costInfo = ""; string details = ""; //Check for valid date input bool isValid = false; string date = year + "-" + month + "-01"; DateTime dt2; if (DateTime.TryParse(date, out dt2)) { isValid = true; int inM = (int)dt2.Month; int inY = (int)dt2.Year; month = inM.ToString(); year = inY.ToString(); } else { isValid = false; } //Get member's meal info foreach (UsersModel u in usList) { List <SelfMealsModel> smList = new List <SelfMealsModel>(); List <GuestMealsModel> gmList = new List <GuestMealsModel>(); SelfMealsModel smm = new SelfMealsModel(); GuestMealsModel gmm = new GuestMealsModel(); smm.memberId = u.id; gmm.memberId = u.id; foreach (SelfMealsModel sm in smm.getAllMealByMemberId()) { smList.Add(sm); } foreach (GuestMealsModel gm in gmm.getAllGuestMealByMemberId()) { gmList.Add(gm); } //List by month and year List <SelfMealsModel> smlistByMonth = new List <SelfMealsModel>(); List <GuestMealsModel> gmlistByMonth = new List <GuestMealsModel>(); //List by month if (isValid) { showing = getMonth(month) + ", " + year; //Get self list by month foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } else { //Get list by current month showing = "Current Month"; month = getCurrentMonth(); year = getCurrentYear(); foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } //Get totals int totalSelf = 0; int totalGuest = 0; foreach (SelfMealsModel s in smlistByMonth) { if (s.breakfast == "1") { totalSelf++; } if (s.lunch == "1") { totalSelf++; } if (s.dinner == "1") { totalSelf++; } } //Calculate guest meals foreach (GuestMealsModel g in gmlistByMonth) { if (g.breakfast == "1") { totalGuest++; } if (g.lunch == "1") { totalGuest++; } if (g.dinner == "1") { totalGuest++; } } //Process subtotal details int subTotalMeals = totalSelf + totalGuest; int subTotalCost = int.Parse(pm.mealrate) * subTotalMeals; details = details + "<tr>" + "<td>" + u.fullname + "</td>" + "<td>" + subTotalMeals + "</td>" + "<td>" + subTotalCost + " Tk</td>" + "</tr>"; ViewBag.Details = details; //Process total cost info totalMeals = totalMeals + subTotalMeals; totalMealCost = totalMealCost + subTotalCost; serviceCharge = serviceCharge + int.Parse(pm.servicecharge); } //Process info totalCost = totalMealCost + serviceCharge; costInfo = costInfo + "<h3 class='text-danger'>Total Meal: <span class='text-success'>" + totalMeals + "</span></h3>" + "<h3 class='text-danger'>Meal Rate: <span class='text-success'>" + pm.mealrate + " Tk</span></h3>" + "<h3 class='text-danger'>Total Meal Cost: <span class='text-success'>" + totalMealCost + " Tk</span></h3>" + "<h3 class='text-danger'>Service Charge: <span class='text-success'>" + serviceCharge + " Tk</span></h3><hr />" + "<h3 class='text-danger'>Total Cost: <span class='text-success'>" + totalCost + " Tk</span></h3>"; ViewBag.CostInfo = costInfo; ViewBag.Showing = showing; } ViewBag.ReportResponse = response; }
private void processMealData() { //Get all member string response = ""; UsersModel usm = new UsersModel(); List <UsersModel> usList = new List <UsersModel>(); foreach (UsersModel user in usm.getAllUsers()) { usList.Add(user); } if (usm.response == "500") { response = "e"; } else { response = "s"; int breakfastT = 0; int lunchT = 0; int dinnerT = 0; int breakfastM = 0; int lunchM = 0; int dinnerM = 0; int breakfastG = 0; int lunchG = 0; int dinnerG = 0; string membersB = ""; string membersL = ""; string membersD = ""; foreach (UsersModel u in usList) { //Collect daily meals SelfMealsModel smm = new SelfMealsModel(); GuestMealsModel gmm = new GuestMealsModel(); smm.memberId = u.id; gmm.memberId = u.id; smm.date = getDate(); gmm.date = getDate(); //List all meals by member List <SelfMealsModel> smList = new List <SelfMealsModel>(); List <GuestMealsModel> gmList = new List <GuestMealsModel>(); foreach (SelfMealsModel sm in smm.getAllMealByMemberIdAndDate()) { smList.Add(sm); } foreach (GuestMealsModel gm in gmm.getAllGuestMealByMemberIdAndDate()) { gmList.Add(gm); } //Get all self meals int sb = 0; int sl = 0; int sd = 0; foreach (SelfMealsModel s in smList) { if (s.breakfast == "1") { sb++; } if (s.lunch == "1") { sl++; } if (s.dinner == "1") { sd++; } } if (sb > 0) { membersB = membersB + "<btn id='b_" + u.id + "' class='btn btn-danger' value='" + Url.Action("cancelBreakfast", new { m = u.id }) + "' name='" + u.fullname + "' onclick='confirmRemovingB(" + u.id + ")'>" + u.fullname + "</btn> "; } if (sl > 0) { membersL = membersL + "<btn id='l_" + u.id + "' class='btn btn-danger' value='" + Url.Action("cancelLunch", new { m = u.id }) + "' name='" + u.fullname + "' onclick='confirmRemovingL(" + u.id + ")'>" + u.fullname + "</btn> "; } if (sd > 0) { membersD = membersD + "<btn id='d_" + u.id + "' class='btn btn-danger' value='" + Url.Action("cancelDinner", new { m = u.id }) + "' name='" + u.fullname + "' onclick='confirmRemovingD(" + u.id + ")'>" + u.fullname + "</btn> "; } breakfastM = breakfastM + sb; lunchM = lunchM + sl; dinnerM = dinnerM + sd; //Get all guest meals int gb = 0; int gl = 0; int gd = 0; foreach (GuestMealsModel g in gmList) { if (g.breakfast == "1") { gb++; } if (g.lunch == "1") { gl++; } if (g.dinner == "1") { gd++; } } breakfastG = breakfastG + gb; lunchG = lunchG + gl; dinnerG = dinnerG + gd; } breakfastT = breakfastM + breakfastG; lunchT = lunchM + lunchG; dinnerT = dinnerM + dinnerG; //Process all data ViewBag.Bt = breakfastT; ViewBag.Lt = lunchT; ViewBag.Dt = dinnerT; ViewBag.Bm = breakfastM; ViewBag.Lm = lunchM; ViewBag.Dm = dinnerM; ViewBag.Bg = breakfastG; ViewBag.Lg = lunchG; ViewBag.Dg = dinnerG; ViewBag.mB = membersB; ViewBag.mL = membersL; ViewBag.mD = membersD; } ViewBag.HomeResponse = response; }
public void autoScheduler() { //Check if auto scheduler has already been started MealSchedulerLogModel ms = new MealSchedulerLogModel(); ms.date = getDate(); bool checkIfAlreadyCheckedToday = ms.checkIfDateExists(); /* * if (ms.response == "500") * { * checkIfAlreadyCheckedToday = true; * } */ if (checkIfAlreadyCheckedToday == false && ms.response == "200") { //Get all not checked dates MealSchedulerLogModel ms2 = new MealSchedulerLogModel(); ms2 = ms2.getLastEntry(); string lastDate = ms2.date; string presentDate = getDate(); //Collect all dates List <string> dates = new List <string>(); DateTime dt = DateTime.ParseExact(lastDate, "dd/MM/yyyy", null); dt = dt.AddDays(1); while (true) { string d = dt.ToString("dd/MM/yyyy"); if (d != presentDate) { dates.Add(d); dt = dt.AddDays(1); } else { dates.Add(d); break; } } //Get all members UsersModel um = new UsersModel(); List <string> allMemberId = new List <string>(); foreach (UsersModel mId in um.getAllUsers()) { allMemberId.Add(mId.id); } //Get all settings SettingsModel sm = new SettingsModel(); List <SettingsModel> smList = new List <SettingsModel>(); foreach (SettingsModel s in sm.getAllSettings()) { smList.Add(s); } //Start adding meals if (ms2.response != "500" || um.response != "500" || sm.response != "500") { string selfmealQuery = ""; string mealLogQuery = ""; foreach (string date in dates) { foreach (string m in allMemberId) { string b = ""; string l = ""; string d = ""; foreach (SettingsModel setting in smList) { if (setting.memberId == m) { b = setting.breakfast; l = setting.lunch; d = setting.dinner; break; } } selfmealQuery = selfmealQuery + "INSERT INTO selfmeals(breakfast, lunch, dinner, memberId, date) VALUES('" + b + "', '" + l + "', '" + d + "', '" + m + "', '" + date + "');"; } mealLogQuery = mealLogQuery + "INSERT INTO mealschedulerlog(date, checked) VALUES('" + date + "','1');"; } SelfMealsModel smm = new SelfMealsModel(); smm.addMultipleMeal(selfmealQuery); MealSchedulerLogModel mlm = new MealSchedulerLogModel(); mlm.addMultipleCheckMark(mealLogQuery); } /* * //Add meals * foreach (string date in dates) * { * foreach (string m in allMemberId) * { * //Get preferences * SettingsModel sm = new SettingsModel(); * sm.memberId = m; * sm = sm.getSettingByMemberId(); * string b = sm.breakfast; * string l = sm.lunch; * string d = sm.dinner; * * //Insert meals * SelfMealsModel smm = new SelfMealsModel(); * string mid = m; * string dT = date; * * smm.memberId = m; * smm.date = date; * bool checkIfAlreadyInserted = smm.checkIfEntryExists(); * * if (checkIfAlreadyInserted == false) * { * smm.memberId = mid; * smm.date = dT; * smm.breakfast = b; * smm.lunch = l; * smm.dinner = d; * smm.addMeal(); * } * } * * MealSchedulerLogModel ms3 = new MealSchedulerLogModel(); * string logDate = date; * * ms3.date = date; * bool checkIfLogged = ms3.checkIfDateExists(); * * if (checkIfLogged == false) * { * ms3.date = logDate; * ms3.check = "1"; * ms3.addCheckMark(); * } * } */ } }
private void processReport(string month, string year) { //Get all meals string response = ""; List <SelfMealsModel> smList = new List <SelfMealsModel>(); List <GuestMealsModel> gmList = new List <GuestMealsModel>(); SelfMealsModel smm = new SelfMealsModel(); GuestMealsModel gmm = new GuestMealsModel(); UserSessionModel usm = (UserSessionModel)Session["user"]; smm.memberId = usm.userid; gmm.memberId = usm.userid; foreach (SelfMealsModel sm in smm.getAllMealByMemberId()) { smList.Add(sm); } foreach (GuestMealsModel gm in gmm.getAllGuestMealByMemberId()) { gmList.Add(gm); } //Get preferences PreferencesModel pm = new PreferencesModel(); pm.getPrefrences(); if (smm.response == "500" || gmm.response == "500" || pm.response == "500") { response = "e"; } else { response = "s"; string showing = ""; string mealInfo = ""; string costInfo = ""; string details = ""; bool isValid = false; List <SelfMealsModel> smlistByMonth = new List <SelfMealsModel>(); List <GuestMealsModel> gmlistByMonth = new List <GuestMealsModel>(); //Check for valid date input string date = year + "-" + month + "-01"; DateTime dt2; if (DateTime.TryParse(date, out dt2)) { isValid = true; int inM = (int)dt2.Month; int inY = (int)dt2.Year; month = inM.ToString(); year = inY.ToString(); } else { isValid = false; } //List by month if (isValid) { showing = getMonth(month) + ", " + year; //Get self list by month foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } else { //Get list by current month showing = "Current Month"; month = getCurrentMonth(); year = getCurrentYear(); foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } //Get totals int totalSelf = 0; int totalGuest = 0; foreach (SelfMealsModel s in smlistByMonth) { int countB = 0; int countL = 0; int countD = 0; int subTotal = 0; int selfB = 0; int selfL = 0; int selfD = 0; if (s.breakfast == "1") { selfB++; } if (s.lunch == "1") { selfL++; } if (s.dinner == "1") { selfD++; } totalSelf = totalSelf + selfB + selfL + selfD; subTotal = subTotal + selfB + selfL + selfD; countB = countB + selfB; countL = countL + selfL; countD = countD + selfD; //Calculate guest meals string d = s.date; foreach (GuestMealsModel g in gmlistByMonth) { int guestB = 0; int guestL = 0; int guestD = 0; if (g.date == d) { if (g.breakfast == "1") { guestB++; } if (g.lunch == "1") { guestL++; } if (g.dinner == "1") { guestD++; } totalGuest = totalGuest + guestB + guestL + guestD; subTotal = subTotal + guestB + guestL + guestD; countB = countB + guestB; countL = countL + guestL; countD = countD + guestD; } } details = details + "<tr>" + "<td>" + d + "</td>" + "<td>" + countB + "</td>" + "<td>" + countL + "</td>" + "<td>" + countD + "</td>" + "<td>" + subTotal + "</td>" + "</tr>"; } //Generate results int totalMeal = totalSelf + totalGuest; mealInfo = "<p><b>Total Meal: <span class='text-success'>" + totalMeal + "</span></b></p>" + "<p><b>Self: <span class='text-success'>" + totalSelf + "</span></b></p>" + "<p><b>Guest: <span class='text-success'>" + totalGuest + "</span></b></p>"; int mealRate = int.Parse(pm.mealrate.Trim()); int serviceCharge = int.Parse(pm.servicecharge.Trim()); int totalMealCost = totalMeal * mealRate; int totalCost = totalMealCost + serviceCharge; costInfo = "<p><b>Meal rate: <span class='text-success'>" + pm.mealrate + " Tk/person</span></b></p>" + "<p><b>Meal cost: <span class='text-success'>" + totalMealCost + " Tk</span></b></p>" + "<p><b>Service charge: <span class='text-success'>" + pm.servicecharge + " Tk/person</span></b></p>" + "<p><b>Total cost: <span class='text-success'>" + totalCost + " Tk</span></b></p>"; ViewBag.Showing = showing; ViewBag.CostInfo = costInfo; ViewBag.Info = mealInfo; ViewBag.Details = details; } ViewBag.ReportResponse = response; }
public ActionResult Registration(string Un, string Uu, string Up, string Pr) { string r = ""; string m = ""; List <string> errList = new List <string>(); UsersModel usm = new UsersModel(); usm.username = Uu; bool isExist = usm.checkIfUsernameExists(); //Check for errors if (Un == "" || Uu == "" || Up == "" || Pr == "") { errList.Add("<li>Please fill all the boxes</li>"); } if (isExist) { errList.Add("<li>User already exists</li>"); } if (Up != Pr) { errList.Add("<li>Passwords didn't match</li>"); } //Action if (errList.Count() < 1) { //Add user UsersModel user = new UsersModel(); user.fullname = Un; user.username = Uu; user.password = Up; user.addUser(); //Get user user = new UsersModel(); user.username = Uu; string uId = user.getUserByUsername().id; //Set settings SettingsModel st = new SettingsModel(); st.breakfast = "0"; st.lunch = "0"; st.dinner = "0"; st.memberId = uId; st.addSettings(); //Set meals SelfMealsModel smm = new SelfMealsModel(); smm.breakfast = "0"; smm.lunch = "0"; smm.dinner = "0"; smm.memberId = uId; smm.date = getDate(); smm.addMeal(); if (user.response == "500" || usm.response == "500" || st.response == "500" || smm.response == "500") { r = "e"; m = "Something went wrong! Try again"; } else { r = "s"; m = "Registration completed successfully! Please login to continue."; } } else { r = "e"; m = "<p>Error!</p><ul>"; foreach (string i in errList) { m = m + i; } m = m + "</ul>"; } return(Json(new { msgtype = r, msg = m })); }