Ejemplo n.º 1
0
 public ActionResult Cancel(int reservationId)
 {
     using (var context = new DataModel.HotelDatabaseContainer())
     {
         Reservation r = context.Reservations.Find(reservationId);
         context.Reservations.Remove(r);
         context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 2
0
 private static void OnTimerElapsed(object sender)
 {
     _job.DoWork(() => {
         var today = DateTime.Now;
         if (today.Month == 12 && today.Day == 31)
         {
             using (var context = new DataModel.HotelDatabaseContainer())
             {
                 var customer = from customers in context.Customers
                                select customers;
                 foreach (var c in customer)
                 {
                     c.stays = 0;
                 }
                 context.SaveChanges();
             }
         }
     });
 }
Ejemplo n.º 3
0
        public ActionResult Reserve(ReservationDetailViewModel rvm)
        {
            var    current   = DateTime.Now;
            string start     = (string)Session["start"];
            var    startTime = DateTime.Parse(start);

            if (current.Subtract(startTime) >= TimeSpan.FromMinutes(10))
            {
                ViewBag.message = "Your reservation time has expired. You will be redirected to the home page. Click 'OK' to continue.";
                return(View());
            }
            else
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        using (var reservationcontext = new DataModel.HotelDatabaseContainer())
                        {
                            DataModel.Reservation r = new DataModel.Reservation();
                            r.checkIn    = rvm.checkIn;
                            r.checkOut   = rvm.checkOut;
                            r.firstName  = rvm.firstName;
                            r.lastName   = rvm.lastName;
                            r.email      = rvm.email;
                            r.phone      = rvm.phone;
                            r.address    = rvm.address;
                            r.city       = rvm.city;
                            r.state      = rvm.state;
                            r.zip        = rvm.zip;
                            r.bill       = rvm.bill;
                            r.guestsInfo = String.Join(";", rvm.guestInfoList.ToArray());
                            r.RoomTypeId = rvm.roomId;
                            if (User.Identity.IsAuthenticated)
                            {
                                r.PersonId = getPersonByEmail().Id;
                            }
                            reservationcontext.Reservations.Add(r);
                            reservationcontext.SaveChanges();
                            Response.Cookies["Reservation"]["Id"] = r.Id.ToString();
                            return(RedirectToAction("Reserve"));
                        }
                    }
                    else
                    {
                        rvm.nights = BizLogic.Utilities.calculateNight(rvm.checkIn, rvm.checkOut);
                        RoomType room = new RoomType();
                        using (var roomcontext = new DataModel.HotelDatabaseContainer())
                        {
                            room = roomcontext.RoomTypes.Find(rvm.roomId);
                        }
                        rvm.roomType  = room.type;
                        rvm.roomGuest = room.maxGuests;
                        return(View("Book", rvm));
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Catch: " + e);
                    return(RedirectToAction("Index"));
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> _RegisterFormPartial_Search(string firstName,
                                                                     string lastName,
                                                                     string email,
                                                                     string address,
                                                                     string city,
                                                                     string state,
                                                                     string zip,
                                                                     string phone,
                                                                     string password)
        {
            RegisterViewModel model = new RegisterViewModel {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email,
                Address   = address,
                City      = city,
                State     = state,
                Zip       = zip,
                Phone     = phone,
                Password  = password
            };

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    DataModel.Customer newUser = new DataModel.Customer
                    {
                        firstName         = model.FirstName,
                        lastName          = model.LastName,
                        email             = model.Email,
                        address           = model.Address,
                        city              = model.City,
                        state             = model.State,
                        zip               = model.Zip,
                        phone             = model.Phone,
                        sessionExpiration = System.DateTime.Now.AddMinutes(10)
                    };

                    using (var context = new DataModel.HotelDatabaseContainer())
                    {
                        context.People.Add(newUser);
                        try
                        {
                            context.SaveChanges();
                            System.Diagnostics.Debug.WriteLine("Added new customer account!");
                        }
                        catch (DbEntityValidationException e)
                        {
                            foreach (var eve in e.EntityValidationErrors)
                            {
                                System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);
                                foreach (var ve in eve.ValidationErrors)
                                {
                                    System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                                       ve.PropertyName, ve.ErrorMessage);
                                }
                            }
                            throw;
                        }
                    }
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(Json(new { registered = "true" }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(PartialView("_RegisterFormPartial"));
        }