Esempio n. 1
0
        public IActionResult Details(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction("index", "home"));
            }

            var selectedCfp = _cfpContext.Cfps.SingleOrDefault(cfp => cfp.Slug == id);

            if (selectedCfp == null)
            {
                // Check it the id happens to be a Guid
                if (Guid.TryParse(id, out Guid guidId))
                {
                    if (guidId != Guid.Empty)
                    {
                        selectedCfp = _cfpContext.Cfps.SingleOrDefault(cfp => cfp.Id == guidId);
                    }
                }

                if (selectedCfp == null)
                {
                    // TODO to error page?
                    return(RedirectToAction("index", "home"));
                }
            }

            if (selectedCfp.DuplicateOfId != null && selectedCfp.DuplicateOfId != Guid.Empty)
            {
                var originalCfp = _cfpContext.Cfps.SingleOrDefault(cfp => cfp.Id == selectedCfp.DuplicateOfId);
                return(RedirectToAction("details", "cfp", new { id = originalCfp.Slug }));
            }

            selectedCfp.Views++;
            _cfpContext.SaveChanges();

            return(View(selectedCfp));
        }
Esempio n. 2
0
        public IActionResult Submit(SubmittedCfp submittedCfp)
        {
            // TODO
            // Check validity
            if (ModelState.IsValid)
            {
                // Map
                var cfpToAddId = Guid.NewGuid();

                var cfpToAdd = new Cfp
                {
                    Id                = cfpToAddId,
                    EventName         = submittedCfp.EventTitle,
                    EventUrl          = submittedCfp.EventUrl,
                    EventImage        = submittedCfp.EventImageUrl,
                    EventDescription  = submittedCfp.EventDescription,
                    EventLocationName = submittedCfp.LocationName,
                    EventLocationLat  = submittedCfp.LocationLat,
                    EventLocationLng  = submittedCfp.LocationLng,
                    CfpEndDate        = submittedCfp.CfpEndDate,
                    CfpAdded          = DateTime.Now
                };

                // Save CFP
                _cfpContext.Add(cfpToAdd);
                _cfpContext.SaveChanges();

                // Post to Twitter

                // Send back ID to do whatever at the client-side
                return(Json(cfpToAddId));
            }

            // Add invalid model
            return(BadRequest());
        }
Esempio n. 3
0
        public async Task <IActionResult> Submit([FromForm] SubmittedCfp submittedCfp)
        {
            // TODO
            // Check validity
            if (ModelState.IsValid)
            {
                // Map
                var cfpToAddId = Guid.NewGuid();
                var timezone   = string.Empty;

                try
                {
                    timezone = await GetTimezone(submittedCfp.LocationLat, submittedCfp.LocationLng);
                }
                catch
                {
                    // Intentionally left blank, just for event to calendar
                    // If it fails, sucks for you
                }

                var cfpToAddSlug = FriendlyUrlHelper.GetFriendlyTitle(submittedCfp.EventTitle);
                var i            = 0;

                // Prevent duplicate slugs
                while (_cfpContext.Cfps.Any(cfp => cfp.Slug == cfpToAddSlug))
                {
                    cfpToAddSlug = $"{cfpToAddSlug}-{++i}";
                }

                var cfpToAdd = new Cfp
                {
                    Id                       = cfpToAddId,
                    EventName                = submittedCfp.EventTitle,
                    EventUrl                 = submittedCfp.EventUrl,
                    EventImage               = ValidateImageUri(submittedCfp.EventImageUrl),
                    EventDescription         = submittedCfp.EventDescription,
                    EventLocationName        = submittedCfp.LocationName,
                    EventLocationLat         = submittedCfp.LocationLat,
                    EventLocationLng         = submittedCfp.LocationLng,
                    CfpEndDate               = submittedCfp.CfpEndDate.Date,
                    CfpAdded                 = DateTime.Now,
                    CfpUrl                   = submittedCfp.CfpUrl,
                    EventStartDate           = submittedCfp.EventStartDate?.Date ?? default(DateTime),
                    EventEndDate             = submittedCfp.EventEndDate?.Date ?? default(DateTime),
                    ProvidesAccommodation    = submittedCfp.ProvidesAccommodation,
                    ProvidesTravelAssistance = submittedCfp.ProvidesTravelAssistance,
                    SubmittedByName          = submittedCfp.SubmittedByName,
                    EventTwitterHandle       = submittedCfp.EventTwitterHandle,
                    EventTimezone            = timezone,
                    Slug                     = cfpToAddSlug,
                    EventTags                = submittedCfp.EventTags
                };

                // Save CFP
                _cfpContext.Add(cfpToAdd);
                _cfpContext.SaveChanges();

                // Post to Twitter account
                try
                {
                    await PostNewCfpTweet(cfpToAdd);
                }
                catch
                {
                    // Intentionally left blank, we can probably do something
                    // more useful, but for now if Twitter fails  ¯\_(ツ)_/¯
                }

                // Send back ID to do whatever at the client-side
                return(Json(cfpToAddId));
            }

            // Add invalid model
            return(BadRequest(submittedCfp));
        }