Example #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }, true);
                    Restaurant restaurant=new Restaurant(){Name = model.RestaurantName,Username = model.UserName,Active = false,Email = model.Email};
                    restaurant.OpenTimes=new List<OpenTime>();
                    restaurant.ClosedDates=new List<CloseDate>();
                    foreach (Days day in (Days[])Enum.GetValues(typeof(Days)))
            {
                OpenTime openTime = new OpenTime() { Day = day };
                restaurant.OpenTimes.Add(openTime);
            }
                    using (EFContext db=new EFContext())
                    {
                        db.Restaurants.Add(restaurant);
                        db.SaveChanges();
                    }

                    //dynamic email = new Email("RegEmail");
                    //email.To = model.Email;
                    //email.UserName = model.UserName;
                    //email.ConfirmationToken = confirmationToken;
                    //email.Send();

                    var mail = new MailMessage("*****@*****.**", model.Email);
                    mail.IsBodyHtml = true;

                    var subject = "Aktivering av konto";
                    var body = "<h2>Hej " + model.UserName + "</h2>!<br/>";
                    body += "För att aktivera ditt konto och registrera en restaurang, vänligen klicka på följande länk:<br/>";
                    //Länk till aktivering, typ "Acivate", "User"

                    Uri uri = System.Web.HttpContext.Current.Request.Url;
                    String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;

                    var myLink = host + "/Account/RegisterConfirmation/" + confirmationToken;

                    mail.Subject = subject;
                    mail.Body = body + Environment.NewLine  + myLink;

                    SmtpClient _client = new SmtpClient();
                    _client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;

                    _client.PickupDirectoryLocation = HttpRuntime.AppDomainAppPath + "EmailContent";

                    _client.Send(mail);

                    return RedirectToAction("RegisterStepTwo", "Account");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #2
0
 private int GetSeats(Restaurant restaurant, IEnumerable<Reservation> reservations, DateTime dateTime)
 {
     var res = reservations.Where(x => x.TimeSlot.Hour == dateTime.Hour || x.TimeSlot.Hour - 1 == dateTime.Hour); //Kolla bokningar för aktuell tid
     var totalGuest = res.Sum(x => x.PersonCount);
     return (restaurant.MaxGuests - totalGuest);
 }
Example #3
0
 public ActionResult EditRestaurant(RestaurantModel model)
 {
     if (ModelState.IsValid)
     {
         Restaurant restaurant = new Restaurant();
         restaurant.Name = model.Name;
         restaurant.Active = model.Active;
         restaurant.Description = model.Description;
         restaurant.Email = model.Email;
         restaurant.Username = User.Identity.Name;
         restaurant.StreetAddress = model.StreetAddress;
         restaurant.City = model.City;
         restaurant.PostalCode = model.PostalCode;
         restaurant.MaxGuests = model.MaxGuests;
         restaurant.OpenTimes = new List<OpenTime>();
         restaurant.OpenTimes = model.OpenTimes.ToList();
         restaurant.Id = model.Id;
         restaurant.MaxPersonsBooking = model.MaxPersonsBooking;
         restaurant.DayCapacity = model.DayCapacity;
         if (model.Image != null)
         {
             if (model.ImageUrl != null) { System.IO.File.Delete(Server.MapPath(model.ImageUrl));}
             string fileName = Guid.NewGuid().ToString() +
                               model.Image.FileName.Substring(model.Image.FileName.LastIndexOf('.'));
             var path = Path.Combine(Server.MapPath("~/Images/UserImages/"), fileName);
             model.Image.SaveAs(path);
             restaurant.ImageUrl = "/Images/UserImages/" + fileName;
         }
         if (model.ClosedDates != null)
         {
             var dates = model.ClosedDates.Split(',');
             restaurant.ClosedDates=new List<CloseDate>();
             foreach (var date in dates)
             {
                 restaurant.ClosedDates.Add(new CloseDate(){ClosedDate = DateTime.Parse(date)});
             }
         }
         _restaurantService.UpdateRestaurant(restaurant);
     }
     return View(model);
 }