Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateEventFormModel model)
        {
            if (model.Start >= model.End)
            {
                ModelState.AddModelError(string.Empty, "Start date cannot be after end date!");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await this.events.CreateAsync(
                model.Name,
                model.Place,
                model.Start,
                model.End,
                model.Tickets,
                model.TicketPrice);

            TempData.AddSuccessMessage($"Event created successfully!");

            this.logger.LogInformation($"Event created: {model.Name}", model);

            return(RedirectToAction(
                       nameof(Web.Controllers.EventsController.All),
                       nameof(EventsController).Replace("Controller", string.Empty),
                       new { area = string.Empty }));
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            this.model = context
                         .ActionArguments
                         .Values
                         .OfType <CreateEventFormModel>()
                         .Single();

            base.OnActionExecuting(context);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateEvent(CreateEventFormModel eventModel)
        {
            var hallExists = hallsServices.HallExists(eventModel.HallId);

            if (!hallExists)
            {
                return(NotFound());
            }



            if (!ModelState.IsValid)
            {
                string rentTimeDisplay = eventsServices.GetRentTimeDisplay(eventModel.RentTime);

                var summaryModel = new SummaryAndPerInfoVM
                {
                    Date                         = eventModel.Date,
                    HallId                       = eventModel.HallId,
                    RentTime                     = eventModel.RentTime,
                    RentTimeDisplay              = rentTimeDisplay,
                    NumberOfPeople               = eventModel.NumberOfPeople,
                    UsingTablesAndChairs         = eventModel.UsingTablesAndChairs,
                    TypeOfEvent                  = eventModel.TypeOfEvent,
                    HallRentalPrice              = eventModel.HallRentalPrice,
                    SecurityCostPerHour          = eventModel.SecurityCostPerHour,
                    ParkingLotSecurityService    = eventModel.ParkingLotSecurityService,
                    ParkingLotSecurityHours      = eventModel.ParkingLotSecurityHours,
                    SecurityStartTime            = eventModel.SecurityStartTime,
                    SecurityEndTime              = eventModel.SecurityEndTime,
                    ParkingLotSecurityPrice      = eventModel.ParkingLotSecurityPrice,
                    TablesAndChairsPrice         = eventModel.TablesAndChairsPrice,
                    TotalPrice                   = eventModel.TotalPrice,
                    FullName                     = eventModel.FullName,
                    Email                        = eventModel.Email,
                    PhoneNumber                  = eventModel.PhoneNumber,
                    TablesAndChairsCostPerPerson = eventModel.TablesAndChairsCostPerPerson,
                    Caterer                      = eventModel.Caterer,
                    EventDescription             = eventModel.EventDescription
                };

                return(View("Summary", summaryModel));
            }


            string tenantId = null;

            User currentUser = await this.userManager.GetUserAsync(User);

            if (currentUser != null)
            {
                tenantId = currentUser.Id;
            }

            this.eventsServices.Create(
                eventModel.HallId,
                tenantId,
                eventModel.Date,
                eventModel.RentTime,
                eventModel.FullName,
                eventModel.Email,
                eventModel.PhoneNumber,
                eventModel.EventStart,
                eventModel.EventEnd,
                eventModel.NumberOfPeople,
                eventModel.UsingTablesAndChairs,
                eventModel.TablesAndChairsCostPerPerson,
                eventModel.SecurityCostPerHour,
                eventModel.ParkingLotSecurityService,
                eventModel.ParkingLotSecurityHours,
                eventModel.SecurityStartTime,
                eventModel.SecurityEndTime,
                eventModel.HallRentalPrice,
                eventModel.TablesAndChairsPrice,
                eventModel.ParkingLotSecurityPrice,
                eventModel.SecurityDeposit,
                eventModel.TotalPrice,
                eventModel.EventDescription,
                eventModel.Caterer,
                eventModel.TypeOfEvent);


            //Send Email to Administration

            string messageBody = this.emailService.GetTextBodyForEmailForReservation(
                eventModel.Date,
                eventModel.FullName,
                eventModel.Email,
                eventModel.PhoneNumber,
                eventModel.NumberOfPeople,
                eventModel.TotalPrice);

            string messageBodyForTenant = this.emailService.GetTextBodyForTenant(
                eventModel.Date,
                eventModel.FullName,
                eventModel.NumberOfPeople,
                eventModel.TotalPrice);

            await this.emailSender.SendEmailAsync(GlobalConstants.HomeEmail, "Reservation request", messageBody);

            await this.emailSender.SendEmailAsync(eventModel.Email, "Reservation request received", messageBodyForTenant);


            return(RedirectToAction(nameof(ReservationSuccessful)));
        }