Exemplo n.º 1
0
        public ActionResult HomePage()
        {
            var photos = homePageService.FetchPhotos().ToList();
            var model  = new List <HomePagePhotoViewModel>(photos.Count);

            for (int i = 1; i <= photos.Count; i++)
            {
                var photo = photos[i - 1];
                if (i < photos.Count)
                {
                    model.Add(HomePagePhotoViewModel.ToViewModel(photo));
                }
                else
                {
                    model.Insert(0, HomePagePhotoViewModel.ToViewModel(photo));
                }
            }

            return(View("_HomePage", model));
        }
Exemplo n.º 2
0
        public ActionResult Create(HomePagePhotoViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var photo = HomePagePhotoViewModel.ToModel(model);
                    homePageService.SavePhoto(photo);

                    return(PartialView("_PhotoPartial", HomePagePhotoViewModel.ToViewModel(photo)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
                this.LogError(ex);
            }

            return(Json(new { Status = MessageMode.Error, Message = "Error occurred until saving photo!" }));
        }