Exemple #1
0
        public static void AddFastFlightReservation(ReservationForm form)
        {
            using (var _context = new DiemServiceDB())
            {
                string caller = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value;
                User   found  = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault();
                if (found.Role != Role.RegisteredUser || found == null || form.FlightId == 0 /*|| form.Seat == 0*/ || form.Passport == 0)
                {
                    throw new Exception("BAD QUERY");
                }

                Flight        wanted = _context.FlightDbSet.Where(u => u.Id == form.FlightId).FirstOrDefault();
                StringBuilder sb     = new StringBuilder(wanted.Seats);
                if (sb[form.Seat] != '5')
                {
                    throw new Exception("NOT AN OFFER");
                }
                sb[form.Seat] = '1';
                wanted.Seats  = sb.ToString();
                FlightReservation fr = _context.FlightReservationDbSet.Add(new FlightReservation(found.Name, found.LastName, form.Seat, form.Passport, found, wanted));
                _context.RegisteredUserDbSet.Where(u => u.Id == found.UlogaID).First().FlightReservations.Add(fr);
                MailServiceManager.SendReservationEmail(fr);
                wanted.Reservations.Add(fr);
                _context.SaveChanges();
            }
        }
Exemple #2
0
 public static void InviteUser(ReservationForm form)
 {
     using (var _context = new DiemServiceDB())
     {
         string caller     = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value;
         User   instigator = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault();
         User   invited    = _context.UserDbSet.Where(u => u.Username == form.InvitedUsername).FirstOrDefault();
         Flight wanted     = _context.FlightDbSet.Where(u => u.Id == form.FlightId).FirstOrDefault();
         if (invited.Role != Role.RegisteredUser || invited == null)
         {
             return;
         }
         FlightReservation fr = _context.FlightReservationDbSet.Add(new FlightReservation(invited.Name, invited.LastName, form.Seat, invited, wanted)
         {
             Invited_By = instigator
         });
         _context.RegisteredUserDbSet.Where(u => u.Id == invited.UlogaID).First().FlightReservations.Add(fr);
         MailServiceManager.SendInvitationEmail(fr);
         _context.SaveChanges();
     }
 }