public UserBLL(Guest guest) { UserID = guest.UserID; E_Mail = guest.E_Mail; Password = guest.Password; FirstName = guest.FirstName; LastName = guest.LastName; Address = guest.Address; ImgUrl = guest.ImgUrl; Discriminator = typeof(Guest).Name; SentFriendshipRequests = new List<FriendshipBLL>(); RecievedFriendshipRequests = new List<FriendshipBLL>(); if(guest.SentFriendshipRequests != null) { foreach (Friendship friendship in guest.SentFriendshipRequests) { SentFriendshipRequests.Add(new FriendshipBLL(friendship)); } foreach (Friendship friendship in guest.RecievedFriendshipRequests) { RecievedFriendshipRequests.Add(new FriendshipBLL(friendship)); } } }
public UserBLL(Guest guest, String forFriendship) { UserID = guest.UserID; E_Mail = guest.E_Mail; Password = guest.Password; FirstName = guest.FirstName; LastName = guest.LastName; Address = guest.Address; }
public UserDBReplica(Guest guest) { UserID = guest.UserID; E_Mail = guest.E_Mail; Password = guest.Password; FirstName = guest.FirstName; LastName = guest.LastName; Address = guest.Address; ImgUrl = guest.ImgUrl; Discriminator = typeof(Guest).Name; if(guest.SentFriendshipRequests != null) { SentFriendshipRequests = guest.SentFriendshipRequests.Cast<Friendship>().ToList(); RecievedFriendshipRequests = guest.RecievedFriendshipRequests.Cast<Friendship>().ToList(); } }
public int ConfirmBookingTable(List<int> tableIndexes, int restaurantID, String date, String time, int duration, int userID, out UserBLL userBLL, out int? reservationID) { Guest guestDAL = new Guest(); int retVal = _restaurantHandlerDAL.ConfirmBookingTable(tableIndexes, restaurantID, date, time, duration, userID, out guestDAL, out reservationID); if(retVal == 0) { userBLL = new UserBLL(guestDAL); } else { userBLL = null; } return retVal; }
public int ConfirmBookingTable(List<int> tableIndexes, int restaurantID, String date, String time, int duration, int userID, out Guest guest, out int? reservationID) { string[] split = time.Split(':'); decimal timeDecimal = Convert.ToDecimal(split[0]); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); DateTime givenDateGBFormat = Convert.ToDateTime(date); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); if(givenDateGBFormat.Date == DateTime.Today.Date) { String d = DateTime.Now.Hour.ToString(); if (Convert.ToDecimal(d) >= timeDecimal) { guest = null; reservationID = 0; return 2; } } List<ReservationRealization> selectedReservations = new List<ReservationRealization>(); try { if (duration == 1) { selectedReservations = (from t in _context.Tables from r in t.ReservationRealizations where EntityFunctions.TruncateTime(r.Date) == EntityFunctions.TruncateTime(givenDateGBFormat) && r.RestaurantID == restaurantID && r.Time == timeDecimal select r).Include(r => r.Table).ToList(); } else if (duration == 2) { selectedReservations = (from t in _context.Tables from r in t.ReservationRealizations where EntityFunctions.TruncateTime(r.Date) == EntityFunctions.TruncateTime(givenDateGBFormat) && r.RestaurantID == restaurantID && (r.Time == timeDecimal || r.Time == timeDecimal + 1) select r).Include(r => r.Table).ToList(); } else if (duration == 3) { selectedReservations = (from t in _context.Tables from r in t.ReservationRealizations where EntityFunctions.TruncateTime(r.Date) == EntityFunctions.TruncateTime(givenDateGBFormat) && r.RestaurantID == restaurantID && (r.Time == timeDecimal || r.Time == timeDecimal + 1 || r.Time == timeDecimal + 2) select r).Include(r => r.Table).ToList(); } else { selectedReservations = (from t in _context.Tables from r in t.ReservationRealizations where EntityFunctions.TruncateTime(r.Date) == EntityFunctions.TruncateTime(givenDateGBFormat) && r.RestaurantID == restaurantID && r.Time == timeDecimal || r.Time == timeDecimal + 1 || r.Time == timeDecimal + 2 || r.Time == timeDecimal + 3 select r).Include(r => r.Table).ToList(); } foreach (ReservationRealization r in selectedReservations) { foreach (int n in tableIndexes) { if (r.Table.CellNumber == n) { if (r.ReservationID != null) { guest = null; reservationID = 0; return 1; } } } } Reservation reservation = new Reservation { GuestID = userID, RestaurantID = restaurantID, ReservationDate = givenDateGBFormat }; _context.Reservations.Add(reservation); foreach (ReservationRealization r in selectedReservations) { foreach (int n in tableIndexes) { if (r.Table.CellNumber == n) { r.ReservationID = reservation.ReservationID; } } } _context.SaveChanges(); guest = _context.Guests.Where(g => g.UserID == userID).Include(g => g.SentFriendshipRequests).Include(g => g.RecievedFriendshipRequests).First(); reservationID = reservation.ReservationID; Invitation invitation = new Invitation() { ReservationID = (int)reservationID, GuestID = userID, Accepted = true}; _context.Invitations.Add(invitation); _context.SaveChanges(); return 0; } catch(DbUpdateConcurrencyException ex) { guest = null; reservationID = 1; return 1; } }