Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. getting an int to — after an action

getting an int to — after an action

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    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");
        }
    
    B 1 Reply Last reply
    0
    • X xnaLearner

      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");
          }
      
      B Offline
      B Offline
      Bull City Rambler
      wrote on last edited by
      #2

      //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 == day2

      I think I'm missing your question tho.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups