No Metadata Documentation available.
Inheritance: ObjectContext
        public ActionResult Available()
        {
            var entities = new DataEntities();
            var latestFeatureDate = entities.Dogs.Max(d => d.DateFeatured);
            var dogs = (
                from dog in entities.Dogs
                where !dog.AdoptedDate.HasValue
                orderby dog.DateFeatured descending
                select new {
                    dog.DogId, dog.Profile, dog.Name, dog.Birthday,
                    dog.DateFeatured, dog.Breed, dog.Gender }
            ).ToList();

            return View(
                from dog in dogs
                select new AdoptableDogViewModel
                {
                    Id = dog.DogId,
                    Profile = dog.Profile,
                    ImageUrl = Url.Action("Image", new { id = dog.DogId }),
                    ThumbnailUrl = Url.Action(
                        "Thumbnail", new { id = dog.DogId }),
                    Name = dog.Name,
                    Age = GetDogAge(dog.Birthday ?? DateTime.Today),
                    Featured =
                        dog.DateFeatured.HasValue
                        && dog.DateFeatured == latestFeatureDate,
                    Breed = dog.Breed,
                    Gender = (dog.Gender ?? "m").ToLower() == "m" ? "Male" : "Female"
                }
            );
        }
        protected override void OnResultExecuting(
            ResultExecutingContext filterContext)
        {
            // Add "Dog of the Week" info to the view bag
            var dog = new DataEntities()
                .Dogs
                .OrderByDescending(d => d.DateFeatured)
                .Select(d => new
                {
                    Id = d.DogId,
                    Name = d.Name,
                    Birthday = d.Birthday, Breed = d.Breed,
                })
                .FirstOrDefault();

            ViewBag.DogOfTheWeek = new DogOfTheWeekSummaryViewModel {
                Id = dog.Id,
                Name = dog.Name,
                ThumbnailUrl = Url.Action(
                    "Image", "Dog", new { id = dog.Id }),
                Age = GetDogAge(dog.Birthday ?? DateTime.Now),
                Breed = dog.Breed
            };

            ViewBag.SupportsTelUrls = Request.Browser.CanInitiateVoiceCall;

            base.OnResultExecuting(filterContext);
        }
        //
        // GET: /NewsStory/Delete/5
        public ActionResult Delete(Guid id)
        {
            var _db = new DataEntities();
            var story = _db.NewsStories.FirstOrDefault(n => n.NewsStoryId == id);

            return View(story);
        }
        //
        // GET: /Events/Details/5
        public ActionResult Details(Guid id)
        {
            var _db = new DataEntities();
            var evt = _db.Events.FirstOrDefault(e => e.EventId == id);

            return View(evt);
        }
        public ActionResult Create(SpecialNeedsStory story)
        {
            ViewBag.exMsg = "";
            try
            {
                if (!ModelState.IsValid) return View();

                // we need to gen the primary key
                story.SpecialNeedsStoryId = Guid.NewGuid();

                if (Request.Files != null & Request.Files.Count > 0)
                {
                    HttpPostedFileBase storyImageFile = Request.Files["image"];
                    if (storyImageFile != null)
                        story.Image = ImageUtils.GetBytes(storyImageFile.InputStream);
                }

                // Add and Save
                var _db = new DataEntities();
                _db.SpecialNeedsStories.AddObject(story);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ViewBag.exMsg = ex.Message;
                return View();
            }
        }
        public ActionResult Delete(Guid id)
        {
            var _db = new DataEntities();
            var content = _db.Contents.FirstOrDefault(e => e.ContentId == id);

            return View(content);
        }
 public ActionResult Image(Guid id)
 {
     var dog = new DataEntities()
         .Dogs
         .FirstOrDefault(d => d.DogId == id);
     if (dog == null || dog.Image == null)
     {
         return File(Server.MapPath("~/content/images/default-dog-pic.png"), "image/png");
     }
     else
     {
         return File(dog.Image, "image/jpeg");
     }
 }
 public ActionResult SpecialNeedsImage(Guid id)
 {
     var story = new DataEntities()
         .SpecialNeedsStories
         .FirstOrDefault(s => s.SpecialNeedsStoryId == id);
     if (story == null || story.Image == null)
     {
         return HttpNotFound();
     }
     else
     {
         return File(story.Image, "image/jpeg");
     }
 }
 public ActionResult Delete(Guid id, FormCollection collection)
 {
     try
     {
         var _db = new DataEntities();
         var story = _db.NewsStories.FirstOrDefault(n => n.NewsStoryId == id);
         _db.DeleteObject(story);
         _db.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
        public ActionResult Delete(Guid id, FormCollection collection)
        {
            try
            {
                var _db = new DataEntities();
                var content = _db.Contents.FirstOrDefault(e => e.ContentId == id);

                _db.DeleteObject(content);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 11
0
        public ActionResult Index()
        {
            var entities = new DataEntities();
            var news =
                from article in entities
                    .NewsStories
                    .OrderByDescending(s => s.DateCreated)
                    .Take(10)
                    .ToList()
                select new NewsOrEventViewModel
                {
                    Id = article.NewsStoryId,
                    Date = article.Date,
                    Title = article.Title,
                    Summary = article.Text,
                    IsEvent = false,
                    SortDate = article.DateCreated
                };

            var events =
                from evt in entities
                    .Events
                    .OrderByDescending(e => e.DateCreated)
                    .Take(10)
                    .ToList()
                select new NewsOrEventViewModel
                {
                    Id = evt.EventId,
                    Date = evt.Date,
                    Location = evt.Location,
                    Title = evt.Name,
                    Summary = evt.Description,
                    IsEvent = true,
                    IsUpcoming =
                        evt.DateCreated.HasValue
                        && evt.DateCreated > DateTime.Now,
                    SortDate = evt.DateCreated
                };

            return View(
                events
                    .Concat(news)
                    .OrderByDescending(i => i.SortDate)
                    .Take(10));
        }
        public ActionResult Create(Content content)
        {
            ViewBag.exMsg = "";
            try
            {
                if (!ModelState.IsValid) return View();

                // we need to gen the primary key
                content.ContentId = Guid.NewGuid();

                // Add and Save
                var _db = new DataEntities();
                _db.Contents.AddObject(content);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ViewBag.exMsg = ex.Message;
                return View();
            }
        }
 //
 // GET: /SpecialNeedsStories/Edit/5
 public ActionResult Edit(Guid id)
 {
     ViewBag.FormType = "Edit";
     var _db = new DataEntities();
     var sns = _db.SpecialNeedsStories.FirstOrDefault(n => n.SpecialNeedsStoryId == id);
     return View(sns);
 }
 public ActionResult Index()
 {
     var _db = new DataEntities();
     var contents = _db.Contents;
     return View(contents);
 }
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            ViewBag.FormType = "Edit";
            ViewBag.exMsg = "";
            try
            {
                if (!ModelState.IsValid) return View();

                var _db = new DataEntities();
                var content = _db.Contents.FirstOrDefault(e => e.ContentId == id);

                UpdateModel(content, collection);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ViewBag.exMsg = ex.Message;
                return View();
            }
        }
        //
        // GET: /Events/
        public ActionResult Index()
        {
            var _db = new DataEntities();
            var events = _db.Events.OrderByDescending(e => e.DateCreated);

            return View(events);
        }
        //
        // GET: /NewsStory/Edit/5
        public ActionResult Edit(Guid id)
        {
            ViewBag.FormType = "Edit";
            var _db = new DataEntities();
            var story = _db.NewsStories.FirstOrDefault(n => n.NewsStoryId == id);

            return View(story);
        }
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            ViewBag.FormType = "Edit";
            ViewBag.exMsg = "";
            try
            {
                if (!ModelState.IsValid) return View();

                var _db = new DataEntities();
                var story = _db.SpecialNeedsStories.FirstOrDefault(n => n.SpecialNeedsStoryId == id);

                UpdateModel(story, collection);

                if (Request.Files != null & Request.Files.Count > 0)
                {
                    HttpPostedFileBase storyImageFile = Request.Files["dogImage"];
                    if (storyImageFile != null && storyImageFile.ContentLength > 0)
                        story.Image = ImageUtils.GetBytes(storyImageFile.InputStream);
                }

                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ViewBag.exMsg = ex.Message;
                return View();
            }
        }
 //
 // GET: /SpecialNeedsStories/Details/5
 public ActionResult Details(Guid id)
 {
     var _db = new DataEntities();
     var story = _db.SpecialNeedsStories.FirstOrDefault(n => n.SpecialNeedsStoryId == id);
     return View(story);
 }
 public ActionResult Image(Guid id)
 {
     var _db = new DataEntities();
     var story = _db.SpecialNeedsStories.FirstOrDefault(n => n.SpecialNeedsStoryId == id);
     if (story == null || story.Image == null)
     {
         return null;
     }
     else
     {
         return File(story.Image, "image/jpeg");
     }
 }
 //
 // GET: /SpecialNeedsStories/
 public ActionResult Index()
 {
     var _db = new DataEntities();
     var stories = _db.SpecialNeedsStories;
     return View(stories);
 }
        public ActionResult Edit(Guid id)
        {
            ViewBag.FormType = "Edit";

            var _db = new DataEntities();
            var content = _db.Contents.FirstOrDefault(e => e.ContentId == id);

            return View(content);
        }
Exemplo n.º 23
0
        public ActionResult Index()
        {
            var entities = new DataEntities();

            var news =
                from article in entities
                    .NewsStories
                    .OrderByDescending(s => s.DateCreated)
                    .Take(10)
                    .ToList()
                select new NewsOrEventSummaryViewModel
                {
                    Id = article.NewsStoryId,
                    Date = article.Date,
                    SortDate = article.DateCreated,
                    Title = article.Title,
                    Summary = article.Text.Summarize(200),
                };

            var events =
                from evt in entities
                    .Events
                    .OrderByDescending(e => e.DateCreated)
                    .Take(10)
                    .ToList()
                select new NewsOrEventSummaryViewModel
                {
                    Id = evt.EventId,
                    Date = evt.Date,
                    SortDate = evt.DateCreated,
                    Title = evt.Name,
                    Summary = evt.Description.Summarize(200),
                };

            var viewData = new HomeIndexViewModel
            {
                NewsAndEvents = news
                    .Concat(events)
                    .OrderByDescending(i => i.SortDate)
                    .Take(10),
            };

            // Load the latest featured dog
            var featuredDog = entities
                .Dogs
                .OrderByDescending(d => d.DateFeatured)
                .Where(d => d.DateFeatured.HasValue)
                .FirstOrDefault();
            if (featuredDog != null)
            {
                viewData.FeaturedDogId = featuredDog.DogId;
                viewData.FeaturedDogThumbnailUrl = Url.Action(
                    "Thumbnail", "Dog",
                    new { id = featuredDog.DogId });
                viewData.FeaturedDogName = featuredDog.Name;
                viewData.FeaturedDogProfile = featuredDog.Profile;
            }

            var featuredNeed = entities
                .SpecialNeedsStories
                .Where(s => s.IsFeatured)
                .OrderByDescending(s => s.DateCreated)
                .FirstOrDefault();
            if (featuredNeed != null)
            {
                viewData.SpecialNeedThumbnailUrl = Url.Action(
                    "SpecialNeedsImage", "News",
                    new { id = featuredNeed.SpecialNeedsStoryId });
                viewData.SpecialNeedDescription = featuredNeed.Text;
            }
            else
            {
                viewData.SpecialNeedDescription = string.Empty;
            }

            return View(viewData);
        }
Exemplo n.º 24
0
 private static Content GetCurrentContent(string area)
 {
     var allSponsorContent = new DataEntities().Contents.Where(c => c.Area.ToLower() == area.ToLower()).OrderByDescending(c => c.PublishOn);
     var defaultSponsor = allSponsorContent.FirstOrDefault<Content>(c => c.IsDefault == true);
     Content content = defaultSponsor;
     foreach (var contentItem in allSponsorContent)
     {
         if (contentItem.PublishOn <= DateTime.Now)
         {
             if (contentItem.PublishUntil.HasValue)
             {
                 if (contentItem.PublishUntil.Value >= DateTime.Now)
                 {
                     // we are in the sweetspot
                     content = contentItem;
                     break;
                 }
                 else
                 {
                     // we are past the publish until date, keep looking
                 }
             }
             else
             {
                 // there's a publish on without an end date, so use it
                 content = contentItem;
                 break; // take the first one
             }
         }
     }
     return content ?? new Content { Markup = "****Coming Soon" };
 }
 //
 // GET: /NewsStory/
 public ActionResult Index()
 {
     var _db = new DataEntities();
     var stories = _db.NewsStories.OrderByDescending(n => n.DateCreated);
     return View(stories);
 }