internal PlaceChildsViewModel Map(Place place)
 {
     var model = new PlaceChildsViewModel
     {
         PlaceTypeEnum = place.PlaceTypeEnum,
         StateChilds = place.StateChilds,
         AttractionChilds = place.AttractionChilds,
         TownCityChilds = place.TownCityChilds
     };
     return model;
 }
Пример #2
0
        public DomainResponse<Place> CreateNewPlace(Place newPlace)
        {
            var response = new DomainResponse<Place>();
            //var tempRelatedPlaces = newPlace.RelatedPlaces != null? newPlace.RelatedPlaces : new List<Place>();
            var tempArticles = newPlace.Articles != null ? newPlace.Articles : new List<Article>();
            var tempSlideShowPics = newPlace.SlideshowPictures != null ? newPlace.SlideshowPictures : new List<Picture>();
            //newPlace.RelatedPlaces = new List<Place>();
            newPlace.Articles = new List<Article>();
            newPlace.SlideshowPictures = new List<Picture>();

            try
            {
                newPlace = _uOW.PlaceRepo.Insert(newPlace);
                _uOW.Save();
                /*foreach (Place place in tempRelatedPlaces)
                {
                    var tempPlace = _uOW.PlaceRepo.GetByID(place.PlaceId);
                    newPlace.RelatedPlaces.Add(tempPlace);
                }*/
                foreach (Article article in tempArticles)
                {
                    var tempArticle = _uOW.ArticleRepo.GetByID(article.ArticleId);
                    newPlace.Articles.Add(tempArticle);
                }
                foreach (Picture picture in tempSlideShowPics)
                {
                    var tempPicture = _uOW.PictureRepo.GetByID(picture.PictureId);
                    newPlace.SlideshowPictures.Add(tempPicture);
                }
                _uOW.Save();
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to create a new article."
                       , null);
            }

            if (newPlace.PlaceId > 0)
            {
                return response.ReturnSuccessResponse(newPlace
                        , new[] { "New article has been successfully created." }
                        , "New article has been successfully created.");
            }
            else
            {
                return response.ReturnFailResponse(new[] { "Error occur while trying to create new article" }
                       , "There is an error trying to save data"
                       , null);
            }
        }
Пример #3
0
 private Article PrepareArticleViewModelToUpdate(ArticleCreateViewModel viewModel)
 {
     var articleIds = !string.IsNullOrEmpty(viewModel.PlacesIdsString) ? viewModel.PlacesIdsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : null;
     var articleObj = viewModel.TransformToArticle();
     foreach (var id in articleIds)
     {
         var place = new Place { PlaceId = int.Parse(id) };
         if(articleObj.Places == null)
             articleObj.Places = new List<Place>();
         articleObj.Places.Add(place);
     }
     return articleObj;
 }
Пример #4
0
        public ActionResult Edit(ArticleCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var articleIds = !string.IsNullOrEmpty(model.PlacesIdsString) ? model.PlacesIdsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : null;
                var articleObj = model.TransformToArticle();
                foreach (var id in articleIds)
                {
                    var place = new Place { PlaceId = int.Parse(id) };
                    if (articleObj.Places == null)
                        articleObj.Places = new List<Place>();
                    articleObj.Places.Add(place);
                }

                var response = _articleManager.EditArticle(articleObj);

                if (response.Success)
                {
                    TempData[Constants.TempdataKeys.EditArticleSuccessKey] = true;
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelErrors("", response.Messages);
                }
            }
            return RedirectToAction("Edit");
        }
Пример #5
0
 public Place TransformToPlaceObject()
 {
     Place placeObj = new Place();
     placeObj.PlaceId = PlaceId.HasValue ? PlaceId.Value : 0;
     placeObj.PlaceName = PlaceName;
     placeObj.Description = Description;
     placeObj.InternalRanking = InternalRanking;
     placeObj.PlaceTypeId = PlaceTypeId.Value;
     placeObj.ParentStateId = ParentStateId;
     placeObj.ParentTownCityId = ParentCityTownId;
     placeObj.ParentAttractionId = ParentAttractionId;
     placeObj.Latitude = Latitude;
     placeObj.Longitude = Longitude;
     return placeObj;
 }
Пример #6
0
        public DomainResponse<BooleanResult> EditPlace(Place newPlace)
        {
            var response = new DomainResponse<BooleanResult>();
            try
            {
                var placeData = _uOW.PlaceRepo.Get(filter: p => p.PlaceId == newPlace.PlaceId, includeProperties: "Articles").FirstOrDefault();
                placeData.PlaceName = newPlace.PlaceName ?? placeData.PlaceName;
                placeData.Description = newPlace.Description ?? placeData.Description;
                placeData.InternalRanking = newPlace.InternalRanking > -1 ? newPlace.InternalRanking : placeData.InternalRanking;
                placeData.PlaceTypeId = newPlace.PlaceTypeId > 0 ? newPlace.PlaceTypeId : placeData.PlaceTypeId;
                placeData.PlaceType = newPlace.PlaceType != null ? newPlace.PlaceType : placeData.PlaceType;

                placeData.ParentStateId = newPlace.ParentStateId.HasValue ? newPlace.ParentStateId : placeData.ParentStateId;
                placeData.ParentTownCityId = newPlace.ParentTownCityId.HasValue ? newPlace.ParentTownCityId : placeData.ParentTownCityId;
                placeData.ParentAttractionId = newPlace.ParentAttractionId.HasValue ? newPlace.ParentAttractionId : placeData.ParentAttractionId;

                //UpdateRelatedPlaces(newPlace, placeData);
                UpdateRelatedArticles(newPlace, placeData);
                UpdateRelatedSlideshowPictures(newPlace, placeData);
                _uOW.PlaceRepo.Update(placeData);
                _uOW.Save();
            }

            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to update data"
                       , new BooleanResult { Success = false });
            }

            return response.ReturnSuccessResponse(new BooleanResult { Success = true }
                    , new[] { "Admin data has been successfully updated." }
                    , "Admin data has been successfully updated.");
        }
Пример #7
0
        private void UpdateRelatedSlideshowPictures(Place newPlace, Place placeToUpdate)
        {
            var pictures = _uOW.PictureRepo.Get();
            var selectedIdsAry = newPlace.SlideshowPictures != null ? newPlace.SlideshowPictures.Select(x => x.PictureId).ToArray() : new int[]{};
            var existingIdsAry = placeToUpdate.SlideshowPictures != null ? placeToUpdate.SlideshowPictures.Select(x => x.PictureId).ToArray() : new int[] { };

            //TODO: make performance testing for this logic
            foreach (Picture picture in pictures)
            {
                if (selectedIdsAry.Contains(picture.PictureId))
                {
                    if (!existingIdsAry.Contains(picture.PictureId))
                        placeToUpdate.SlideshowPictures.Add(picture);
                }
                else
                {
                    if (existingIdsAry.Contains(picture.PictureId))
                        placeToUpdate.SlideshowPictures.Remove(picture);
                }
            }
        }
Пример #8
0
 /* private void UpdateRelatedPlaces(Place newPlace, Place placeToUpdate)
 {
     var places = _uOW.PlaceRepo.Get();
     var selectedIdsAry = newPlace.RelatedPlaces != null ? newPlace.RelatedPlaces.Select(x => x.PlaceId).ToArray() : new int[]{};
     var existingIdsAry = placeToUpdate.RelatedPlaces != null ? placeToUpdate.RelatedPlaces.Select(x => x.PlaceId).ToArray() : new int[]{};
     foreach (Place place in places)
     {
         if (selectedIdsAry.Contains(place.PlaceId))
         {
             if (!existingIdsAry.Contains(place.PlaceId))
                 placeToUpdate.RelatedPlaces.Add(place);
         }
         else
         {
             if (existingIdsAry.Contains(place.PlaceId))
                 placeToUpdate.RelatedPlaces.Remove(place);
         }
     }
 }*/
 private void UpdateRelatedArticles(Place newPlace, Place placeToUpdate)
 {
     var articles = _uOW.ArticleRepo.Get();
     var selectedIdsAry = newPlace.Articles != null ? newPlace.Articles.Select(x => x.ArticleId).ToArray() : new int[]{};
     var existingIdsAry = placeToUpdate.Articles != null ? placeToUpdate.Articles.Select(x => x.ArticleId).ToArray() : new int[]{};
     foreach (Article article in articles)
     {
         if (selectedIdsAry.Contains(article.ArticleId))
         {
             if (!existingIdsAry.Contains(article.ArticleId))
                 placeToUpdate.Articles.Add(article);
         }
         else
         {
             if (existingIdsAry.Contains(article.ArticleId))
                 placeToUpdate.Articles.Remove(article);
         }
     }
 }