Example #1
0
        public async Task <bool> CreateEvent(EventCreateInputModel eventModel)
        {
            Publication publication = new Publication
            {
                CreatedOn = DateTime.UtcNow,
                Title     = eventModel.PublicationTitle,
                UserId    = eventModel.PublicationUserId,
            };

            await this.context.Publications.AddAsync(publication);

            Event newEvent = new Event
            {
                Description   = eventModel.Description,
                Address       = eventModel.Address,
                StartTime     = eventModel.StartTime,
                EndTime       = eventModel.EndTime,
                CategoryId    = eventModel.CategoryId,
                PublicationId = publication.Id,
            };

            await this.context.Events.AddAsync(newEvent);

            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Example #2
0
        public async Task <ActionResult> Create([FromBody] EventCreateInputModel inputModel)
        {
            var userId = User.GetCurrentUserId();
            var result = await this.eventService.CreateAsync(inputModel.Title, inputModel.Description, inputModel.PictureUrl, inputModel.When, inputModel.NightClubId);

            return(this.Created(nameof(Create), result));
        }
        public async Task <IActionResult> Create(EventCreateInputModel inputModel)
        {
            var location  = this.GetLocation();
            var countryId = await this.countriesService.GetIdAsync(location.Country);

            var cityId = await this.citiesService.GetIdAsync(location.City, countryId);

            if (!this.ModelState.IsValid)
            {
                inputModel.Arenas = await this.arenasService.GetAllActiveInCitySelectListAsync(cityId);

                inputModel.Sports = await this.sportsService.GetAllInCountryByIdAsync(countryId);

                inputModel.Date = DateTime.UtcNow;

                return(this.View(inputModel));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var id = await this.eventsService.CreateAsync(
                inputModel, cityId, countryId, user.Id, user.Email, user.UserName);

            this.TempData[TempDataMessage] = EventCreated;

            return(this.RedirectToAction(nameof(this.Details), new { id }));
        }
        public void Add(EventCreateInputModel eventCreateInput)
        {
            Event validEvent = eventCreateInput.To <Event>();

            context.Events.Add(validEvent);
            context.SaveChanges();
        }
Example #5
0
        public IActionResult Create()
        {
            var users     = this.usersService.GetAll <UserDropDownViewModel>();
            var viewModel = new EventCreateInputModel
            {
                Users = users,
            };

            return(this.View(viewModel));
        }
        private EventCreateInputModel GetEventDateTimeProperties()
        {
            var model = new EventCreateInputModel
            {
                StartDate = DateTime.UtcNow.AddDays(AddDays).AddMinutes(AddMinutes),
                EndDate   = DateTime.UtcNow.AddDays(AddDays).AddHours(AddHours).AddMinutes(AddMinutes)
            };

            return(model);
        }
        public async Task <IActionResult> Create(EventCreateInputModel model)
        {
            var creator = await this.userManager.GetUserAsync(this.User);

            var eventId = await this.events.CreateAsync(model.Title, model.Description, model.StartDate,
                                                        model.EndDate, model.PictureFile, model.Address, model.Latitude, model.Longitude, creator.Id);

            return(this.RedirectToAction("Details", "Events", new { Area = "Events", id = eventId })
                   .WithSuccess(string.Empty, EventCreationSuccess));
        }
        public IActionResult Create(EventCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            eventService.Add(model);
            return(RedirectToAction("All"));
        }
Example #9
0
        public IActionResult Create(EventCreateInputModel model)
        {
            if (!this.ModelState.IsValid || model.End < model.Start)
            {
                return(this.View(model));
            }

            var mappedModel = this.mapper.Map <EventCreateDTO>(model);

            this.eventsService.Create(mappedModel);

            return(this.Redirect("/"));
        }
        public async Task <IActionResult> Create()
        {
            var categories = await this.categoriesService
                             .GetAllCategories <AllCategoriesViewModel>();

            var userId = this.userManager.GetUserId(this.User);
            var eventCreateInputModel = new EventCreateInputModel
            {
                PublicationUserId = userId,
                AllCategories     = categories,
            };

            return(this.View(eventCreateInputModel));
            // return this.Json(eventCreateInputModel);
        }
        public async Task <IActionResult> Create()
        {
            var location  = this.GetLocation();
            var countryId = await this.countriesService.GetIdAsync(location.Country);

            var cityId = await this.citiesService.GetIdAsync(location.City, countryId);

            var viewModel = new EventCreateInputModel
            {
                Arenas = await this.arenasService.GetAllActiveInCitySelectListAsync(cityId),
                Sports = await this.sportsService.GetAllInCityByIdAsync(cityId),
                Date   = DateTime.UtcNow,
            };

            return(this.View(viewModel));
        }
        public void EventCreateInputModelShouldHaveTitle()
        {
            var eventToTest = new EventCreateInputModel
            {
                Title       = null,
                Start       = DateTime.UtcNow,
                Description = "ddd",
                Color       = "sss",
                End         = DateTime.Now,
                IsAllDay    = false,
                IsRecurring = false,
            };

            var validatorResults = new List <ValidationResult>();
            var actual           = Validator.TryValidateObject(eventToTest, new ValidationContext(eventToTest), validatorResults, true);

            Assert.False(actual);
            Assert.Single(validatorResults);
        }
Example #13
0
        public async Task <IActionResult> Create(EventCreateInputModel eventCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(eventCreateInputModel));
            }

            string fileUrl = await this.cloudinaryService.UploadFile(eventCreateInputModel.MoreInfo, eventCreateInputModel.Name);

            EventServiceModel eventServiceModel = new EventServiceModel()
            {
                Name     = eventCreateInputModel.Name,
                Start    = eventCreateInputModel.Start,
                Venue    = eventCreateInputModel.Venue,
                MoreInfo = fileUrl
            };

            await this.eventsService.Create(eventServiceModel);

            return(this.Redirect("/"));
        }
        public async Task <IActionResult> Create(EventCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var userId = this.userManager.GetUserId(this.User);

            model.PublicationUserId = userId;

            bool isCreted = await this.eventsService.CreateEvent(model);

            if (!isCreted)
            {
                return(this.View(model));
            }

            return(this.Redirect("/Events/All"));
            //return this.Json(model);
        }
Example #15
0
        public async Task <IActionResult> Create(EventCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var eventId = await this.eventsService.CreateAsync(
                input.Title,
                input.Description,
                input.Start,
                input.End,
                input.IsAllDay,
                input.IsRecurring,
                user.Id,
                input.Color,
                input.AssignedUsersId);

            return(this.Redirect("/"));
        }
Example #16
0
        public async Task <int> CreateAsync(
            EventCreateInputModel inputModel, int cityId, int countryId, string userId, string userEmail, string username)
        {
            var @event = inputModel.To <Event>();

            @event.CityId    = cityId;
            @event.CountryId = countryId;
            @event.AdminId   = userId;
            await this.eventsRepository.AddAsync(@event);

            await this.eventsRepository.SaveChangesAsync();

            await this.eventsUsersRepository.AddAsync(new EventUser
            {
                EventId = @event.Id,
                UserId  = userId,
            });

            await this.eventsUsersRepository.SaveChangesAsync();

            var eventId = @event.Id;

            await this.messagesService.CreateAsync(EventCreationMessage, userId, eventId);

            var sportName = await this.sportsService.GetNameByIdAsync(inputModel.SportId);

            await this.emailSender.SendEmailAsync(
                userEmail,
                EmailSubjectConstants.EventCreated,
                EmailHtmlMessages.GetEventCreationHtml(
                    username,
                    inputModel.Name,
                    sportName,
                    inputModel.Date.ToString(DefaultDateFormat),
                    inputModel.StartingHour.ToString(DefaultTimeFormat)));

            return(eventId);
        }
        public async Task CreateAsyncAddEventToDb()
        {
            var inputModel = new EventCreateInputModel
            {
                AdminId         = this.userId,
                ArenaId         = 1,
                SportId         = 1,
                Date            = DateTime.UtcNow.AddMonths(3),
                StartingHour    = DateTime.UtcNow.AddMonths(3),
                MinPlayers      = 4,
                MaxPlayers      = 10,
                DurationInHours = 2,
                Name            = "ThirdEvent",
                Gender          = Gender.Any,
                RequestStatus   = ArenaRequestStatus.NotSent,
            };

            await this.Service.CreateAsync(inputModel, 1, 1, this.userId, "email", "username");

            Assert.Equal(4, this.DbContext.Events.Count());
            Assert.Equal(2, this.DbContext.EventsUsers.Count());
            Assert.Equal(2, this.DbContext.Messages.Count());
        }