getting an int to — after an action
-
so in my person table...I have Id, Name & HolidaysRemaining. Its for a holiday booking application, and atm when a user selects dates from a calendar and clicks the button, each date selected will be stored in the DB, I am trying to minus the holidays remaining by 1, as each holiday is booked, but it doesn't seem to be picking up.
//listHolidays in correct format dd/mm/yy
[HttpPost]
public ActionResult listHolidays(Holiday holiday, Person person, int? PersonId, string HolidayDate, string endDate, string AlreadyExists)
{
//int holidaysRemaining = 20;
//person.HolidaysRemaining = holidaysRemaining;DateTime startDates = Convert.ToDateTime(HolidayDate); DateTime endDates = Convert.ToDateTime(endDate); while (startDates <= endDates) { if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday) { //if user selects Holiday that already exists, wont add it to Db //gets string, and uses the previously converted to dateTime 'startDate' //id so only applies to person creating holidays ViewBag.CantDuplicateHolidays = String.IsNullOrEmpty(AlreadyExists) ? "date" : ""; var dates = from d in db.Holidays where d.HolidayDate == startDates && d.PersonId == PersonId select d; // <= 0..so if holiday does not already exist if (dates.Count() <= 0) { // holidaysRemaining--; person.HolidaysRemaining--; Holiday holiday1 = new Holiday(); holiday1.PersonId = PersonId.Value; holiday1.HolidayDate = startDates; db.Holidays.AddObject(holiday1); db.SaveChanges(); //say start date is 10. AddDays(1) will make it 11 then return it to startDates in 'startDates' = startdates, //but doesnt chage the value of startdates = 'startdates' } } startDates = startDates.AddDays(1); } return RedirectToAction("Index"); }
-
so in my person table...I have Id, Name & HolidaysRemaining. Its for a holiday booking application, and atm when a user selects dates from a calendar and clicks the button, each date selected will be stored in the DB, I am trying to minus the holidays remaining by 1, as each holiday is booked, but it doesn't seem to be picking up.
//listHolidays in correct format dd/mm/yy
[HttpPost]
public ActionResult listHolidays(Holiday holiday, Person person, int? PersonId, string HolidayDate, string endDate, string AlreadyExists)
{
//int holidaysRemaining = 20;
//person.HolidaysRemaining = holidaysRemaining;DateTime startDates = Convert.ToDateTime(HolidayDate); DateTime endDates = Convert.ToDateTime(endDate); while (startDates <= endDates) { if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday) { //if user selects Holiday that already exists, wont add it to Db //gets string, and uses the previously converted to dateTime 'startDate' //id so only applies to person creating holidays ViewBag.CantDuplicateHolidays = String.IsNullOrEmpty(AlreadyExists) ? "date" : ""; var dates = from d in db.Holidays where d.HolidayDate == startDates && d.PersonId == PersonId select d; // <= 0..so if holiday does not already exist if (dates.Count() <= 0) { // holidaysRemaining--; person.HolidaysRemaining--; Holiday holiday1 = new Holiday(); holiday1.PersonId = PersonId.Value; holiday1.HolidayDate = startDates; db.Holidays.AddObject(holiday1); db.SaveChanges(); //say start date is 10. AddDays(1) will make it 11 then return it to startDates in 'startDates' = startdates, //but doesnt chage the value of startdates = 'startdates' } } startDates = startDates.AddDays(1); } return RedirectToAction("Index"); }
//but doesnt chage the value of startdates = 'startdates'
I'm confused about what you mean here. Are you expecting one DateTime value to change because of a change to a different DateTime value? If so, that won't happen because DateTime is a struct, meaning
DateTime foo = day1;
DateTime bar = foo; // bar == day1, foo == day1
foo = day2; // bar == day1, foo == day2I think I'm missing your question tho.