private dynamic SaveBooking(Booking Modell, int BookingID) { try { foreach (DateRequested items in Modell.DateRequesteds) { items.BookingID = BookingID; db.DateRequesteds.Add(items); //findSchedule.BookingID = BookingID; //findSchedule.StatusID = 2; db.SaveChanges(); } //if(Modell.Client.Sales.) foreach (BookingLine items in Modell.BookingLines) { BookingLine line = new BookingLine(); line.BookingID = BookingID; line.ServiceID = items.ServiceID; if (items.OptionID != null) { line.OptionID = items.OptionID; } db.BookingLines.Add(line); db.SaveChanges(); } foreach (BookingNote items in Modell.BookingNotes) { BookingNote notes = new BookingNote(); notes.Note = items.Note; notes.BookingID = BookingID; } return("success"); } catch (Exception err) { return(err.Message); } }
public dynamic MakeBooking(dynamic Bookings) { string SessionID = Bookings.SessionID; User findUser = db.Users.Where(zz => zz.SessionID == SessionID).FirstOrDefault(); if (findUser != null) { try { string name = Bookings.Clients.Name; string surname = Bookings.Clients.Surname; string email = Bookings.Clients.Email; string contact = Bookings.Clients.ContactNo; int SeriviceID = (int)Bookings.BookingLines[0].ServiceID; int OptionID = (int)Bookings.BookingLines[0].OptionID; string notes = Bookings.BookingNotes.Notes; int DateID = (int)Bookings.EmployeeSchedule[0].DateID; int TimeID = (int)Bookings.EmployeeSchedule[0].TimeID; int EmployeeID = (int)Bookings.EmployeeSchedule[0].EmployeeID; int ClientID = 0; Client newClient = db.Clients.Where(zz => zz.Name == name && zz.Surname == surname).FirstOrDefault(); if (newClient == null) { newClient.Name = name; newClient.Surname = surname; newClient.Email = email; newClient.ContactNo = contact; db.Clients.Add(newClient); ClientID = newClient.ClientID; } else { ClientID = newClient.ClientID; } Booking saveBooking = new Booking(); saveBooking.ClientID = ClientID; saveBooking.StatusID = 1; saveBooking.ReminderID = 1; db.SaveChanges(); int BookingID = saveBooking.BookingID; BookingLine saveLine = new BookingLine(); saveLine.BookingID = BookingID; saveLine.ServiceID = SeriviceID; if (OptionID != 0) { saveLine.OptionID = OptionID; } BookingNote saveNotes = new BookingNote(); if (notes != null) { saveNotes.Note = notes; saveNotes.BookingID = BookingID; } } catch { return("client details are invalid"); } return("success"); } else { return("Session is no longer valid"); } }