Example #1
0
        public ActionResult CreateNewRoom()
        {
            var newRoomNumber = new Random()
                                .ToEnumerable(r => r.Next(100, 10000))
                                .First(n => this.Db.Rooms.Any(room => room.RoomNumber == n) == false);

            var urlOfThisRoom      = Url.AppUrl() + Url.Action("Room", new { id = newRoomNumber });
            var bitly              = Bitly.Default;
            var shortUrlOfThisRoom = bitly.Status == Bitly.StatusType.Available ?
#if DEBUG
                                     bitly.ShortenUrl("http://asktheaudiencenow.azurewebsites.net/Room/" + newRoomNumber.ToString()) : "";
#else
                                     bitly.ShortenUrl(urlOfThisRoom) : "";
#endif

            var options = new[] {
                new Option {
                    DisplayOrder = 1, Text = "Yes"
                },
                new Option {
                    DisplayOrder = 2, Text = "No"
                },
            }.ToList();

            this.Db.Rooms.Add(new Room
            {
                RoomNumber  = newRoomNumber,
                OwnerUserID = this.User.Identity.Name,
                Options     = options,
                Url         = urlOfThisRoom,
                ShortUrl    = shortUrlOfThisRoom
            });
            this.Db.SaveChanges();

            return(RedirectToAction("Room", new { id = newRoomNumber }));
        }