forum

Home / DeveloperSection / Forums / Add to exisiting Database instance from MVC Controller

Add to exisiting Database instance from MVC Controller

Anonymous User 2145 30-Nov-2014
Private BookingDB db = new BookingDB();
        Private MonthDb mdb = new MonthDB();
 
        if (ModelState.IsValid)
        {
            String date = (booking.Start_Date).ToString();
 
            var check = from b in mdb.months
                        where b.BookedDays.Contains(date)
                        select b;
 
            if (check != null)
            {
                return View(booking);
            }
            else
            {
                booking.Reservation_Owner = User.Identity.Name;
 
                //Add booking.Start_Date to mdb.Entry(check).BookedDays
 
                mdb.SaveChanges();
                db.bookings.Add(booking);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }

I've got this code that on creation of a new booking, will check that no exisiting bookings have already been made on or around that specific day. if the day to be booked is not already been booked (ie exists under BookedDays in mdb.months) then i wish to add the Start_Date of the booking, to the BookedDays string in the mdb.months database (the mdb.month database is just a list of the 12 months)

at first i tried using mdb.Entry() to add to that specific month instance, however i cannot get it to work. 

the error is:

the model does not have a definition for BookedDays

what to do?


Updated on 01-Dec-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By