public Picture AddNewPhoto(Picture photo) { try { photo = _uOW.PictureRepo.Insert(photo); _uOW.Save(); } catch (Exception ex) { return photo; } return photo; }
internal Picture Map(PhotoViewModel viewModel) { var picture = new Picture { FileName = viewModel.FileName, OwnerName = viewModel.OwnerName, Title = viewModel.Title, Description = viewModel.Description, PictureSourceId = viewModel.SourceId, ImageUrl = viewModel.ImageUrl }; return picture; }
internal PhotoViewModel Map(Picture pic, UrlHelper url) { var picture = new PhotoViewModel { PictureId = pic.PictureId.ToString(), FileName = pic.FileName, OwnerName = pic.OwnerName, Title = pic.Title, Description = pic.Description, SourceId = pic.PictureSourceId, ImageUrl = pic.PictureSourceId == 1 ? url.Content("~/Content/Upload/" + pic.FileName) : pic.ImageUrl }; return picture; }
private Place PreparePlaceViewModelToUpdate(PlaceViewModel viewModel) { var articleIds = !string.IsNullOrEmpty(viewModel.RelatedArticleIds) ? viewModel.RelatedArticleIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[]{}; var placeIds = !string.IsNullOrEmpty(viewModel.RelatedPlaceIds) ? viewModel.RelatedPlaceIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; var slideShowPicIds = !string.IsNullOrEmpty(viewModel.RelatedSlideShowPictureIds) ? viewModel.RelatedSlideShowPictureIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; var placeObj = viewModel.TransformToPlaceObject(); foreach (var id in articleIds) { var article = new Article { ArticleId = int.Parse(id) }; if (placeObj.Articles == null) placeObj.Articles = new List<Article>(); placeObj.Articles.Add(article); } /*foreach (var id in placeIds) { var place = new Place { PlaceId = int.Parse(id) }; if (placeObj.RelatedPlaces == null) placeObj.RelatedPlaces = new List<Place>(); placeObj.RelatedPlaces.Add(place); }*/ foreach (var id in slideShowPicIds) { var picture = new Picture { PictureId = int.Parse(id) }; if (placeObj.SlideshowPictures == null) placeObj.SlideshowPictures = new List<Picture>(); placeObj.SlideshowPictures.Add(picture); } return placeObj; }