public ActionResult PostEvent()
        {
            var user = UserManager.FindByNameAsync(User.Identity.Name).Result;

            ClaimsIdentity identity = UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie).Result;

            if (!identity.HasClaim(e => e.Type == "IsOrganizer" && e.Value == "true"))
            {
                return(RedirectToAction("OrganizerInformation", "Account", new { name = User.Identity.Name }));
            }
            var model          = new PostEventViewModel();
            var eventTypesTask = Repository.EventTypes.AllAsync();
            var sportsTask     = Repository.Sports.AllAsync();
            var countriesTask  = Repository.Countries.AllAsync();

            Task.WaitAll(eventTypesTask, sportsTask, countriesTask);
            model.EventTypes = eventTypesTask.Result;
            model.Sports     = sportsTask.Result;
            model.Countries  = countriesTask.Result;
            model.Cities     = new List <City>();
            model.BeginDate  = DateTime.Now;
            model.EndDate    = DateTime.Now;
            model.BeginTime  = DateTime.Now;
            model.EndTime    = DateTime.Now;

            return(View(model));
        }
        public async Task <ActionResult> PostEvent(PostEventViewModel model)
        {
            var user = UserManager.FindByNameAsync(User.Identity.Name).Result;

            ClaimsIdentity identity = UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie).Result;

            if (!identity.HasClaim(e => e.Type == "IsOrganizer" && e.Value == "true"))
            {
                return(RedirectToAction("OrganizerInformation", "Account", new { name = User.Identity.Name }));
            }
            if (ModelState.IsValid)
            {
                var city = await Repository.Cities.GetAsync(model.CityId);

                var eventType = await Repository.EventTypes.GetAsync(model.EventTypeId);

                var sport = await Repository.Sports.GetAsync(model.SportId);

                var address = new Address()
                {
                    CityId      = model.CityId ?? 0,
                    CountryName = city.CountryName,
                    Zip         = model.Zip,
                    LineTwo     = model.AddressLineTwo,
                    LineOne     = model.AddressLineOne,
                    CityName    = city.Name
                };
                byte[] icon = null;
                using (var inputStream = model.Icon?.InputStream)
                {
                    var memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        var copyToAsync = inputStream?.CopyToAsync(memoryStream);
                        if (copyToAsync != null)
                        {
                            await copyToAsync;
                        }
                    }
                    icon = memoryStream.ToArray();
                }
                var @event = new Event()
                {
                    OrganizerId   = User.Identity.GetUserId(),
                    Address       = address,
                    AddressString = address.ToString(),
                    BeginDate     = model.BeginDate,
                    BeginTime     = model.BeginTime,
                    EndTime       = model.EndTime,
                    EndDate       = model.EndDate,
                    Description   = model.Title,
                    EventTypeId   = eventType.Id,
                    EventTypeName = eventType.Name,
                    SportId       = sport.Id,
                    CityId        = city.Id,
                    SportName     = sport.Name,
                    Details       = model.Description,
                    VideoLink     = model.VideoLink,
                    StartingPrice = model.Price,
                    Icon          = icon,
                    ExternalLink  = model.SocialMediaLink,
                    OrganizerName = user.UserName,
                };
                Console.WriteLine(await Repository.Events.AddAsync(@event));
                return(RedirectToAction("Dashboard", "Organizer"));
            }
            var eventTypesTask = Repository.EventTypes.AllAsync();
            var sportsTask     = Repository.Sports.AllAsync();
            var countriesTask  = Repository.Countries.AllAsync();
            var cityTask       = Repository.Cities.AllAsync();

            Task.WaitAll(eventTypesTask, sportsTask, countriesTask, cityTask);
            model.EventTypes = eventTypesTask.Result;
            model.Sports     = sportsTask.Result;
            model.Countries  = countriesTask.Result;

            model.Cities = cityTask.Result;
            return(View(model));
        }