Ejemplo n.º 1
0
        public DomainResponse<BooleanResult> ChangeAdminPassword(int adminId, string newPassword)
        {
            var response = new DomainResponse<BooleanResult>();
            if (adminId <= 0)
                return response.ReturnFailResponse(new []{"Data cannot be retrieve with AdminId NULL"}
                    ,"There is an error trying to retrieve data"
                    ,new BooleanResult { Success = false });

            var resultAdmin = _uOW.AdminRepo.Get(u => u.AdminId == adminId).SingleOrDefault();
            resultAdmin.Password = newPassword;
            try
            {
                _uOW.AdminRepo.Update(resultAdmin);
                _uOW.Save();
            }
            catch(Exception ex)
            {
                return response.ReturnFailResponse( new[] { ex.Message }
                    , "There is an error trying to retrieve data"
                    , new BooleanResult { Success = false });
            }

            return response.ReturnSuccessResponse(new BooleanResult { Success = true }
                    , new[] { "Password has been successfully updated." }
                    , "Password has been successfully updated.");
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        public DomainResponse<Article> CreateNewArticle(Article newArticle)
        {
            var response = new DomainResponse<Article>();
            var tempRelatedPlaces = newArticle.Places;
            newArticle.Places = new List<Place>();
            newArticle.LastUpdatedDate = DateTime.Now;
            try
            {
                newArticle = _uOW.ArticleRepo.Insert(newArticle);
                _uOW.Save();
                foreach (Place place in tempRelatedPlaces)
                {
                    var tempPlace = _uOW.PlaceRepo.GetByID(place.PlaceId);
                    newArticle.Places.Add(tempPlace);
                }
                _uOW.Save();
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to create a new article."
                       , null);
            }

            if (newArticle.ArticleId > 0)
            {

                return response.ReturnSuccessResponse(newArticle
                        , 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);
            }
        }
Ejemplo n.º 4
0
        public DomainResponse<IEnumerable<Picture>> SearchPictures(string searchTerm, IEnumerable<int> articleIdsToExclude)
        {
            var response = new DomainResponse<IEnumerable<Picture>>();
            try
            {
                var pictures = _uOW.PictureRepo.Get(p => !articleIdsToExclude.Contains(p.PictureId) && (p.Title.Contains(searchTerm) || p.Description.Contains(searchTerm)));
                response.Result = pictures.ToArray();
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to retrieve data", null);
            }

            return response.ReturnSuccessResponse(response.Result, null, null);
        }
Ejemplo n.º 5
0
        public DomainResponse<BooleanResult> EditArticle(Article article)
        {
            var response = new DomainResponse<BooleanResult>();
            try
            {
                var articleData = _uOW.ArticleRepo.Get(filter: ai => ai.ArticleId == article.ArticleId, includeProperties: "Places").FirstOrDefault();
                articleData.ArticleName = article.ArticleName ?? articleData.ArticleName;
                articleData.Title = article.Title ?? articleData.Title;
                articleData.CreatedDate = article.PublishDate != DateTime.MinValue ? article.PublishDate : articleData.CreatedDate;
                articleData.LastUpdatedDate = article.LastUpdatedDate != DateTime.MinValue ? article.LastUpdatedDate : articleData.LastUpdatedDate;
                articleData.PublishDate = article.PublishDate != DateTime.MinValue ? article.PublishDate : articleData.PublishDate;
                articleData.Content = article.Content;
                UpdateArticlePlaces(article, articleData);
                _uOW.ArticleRepo.Update(articleData);
                _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.");
        }
Ejemplo n.º 6
0
        public DomainResponse<IEnumerable<Article>> SearchArticls(string searchTerm, IEnumerable<int> articleIdsToExclude)
        {
            var response = new DomainResponse<IEnumerable<Article>>();
            try
            {
                var articles = _uOW.ArticleRepo.Get(p => !articleIdsToExclude.Contains(p.ArticleId) && p.ArticleName.Contains(searchTerm));
                response.Result = articles.ToArray();
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to retrieve data", null);
            }

            return response.ReturnSuccessResponse(response.Result, null, null);
        }
Ejemplo n.º 7
0
        public DomainResponse<Article> GetArticleById(int id)
        {
            var response = new DomainResponse<Article>();
            try
            {
                response.Result = _uOW.ArticleRepo.GetArticleById(id);
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to retrieve data", null);
            }

            if (response.Result != null)
                return response.ReturnSuccessResponse(response.Result, null, null);
            else
                return response.ReturnFailResponse(new[] { string.Format("Error occur whilte retrieving data for admingId {0}", id) }
                    , "There is an error trying to retrieve data", null);
        }
Ejemplo n.º 8
0
        public DomainResponse<BooleanResult> EditAdmin(Admin admin)
        {
            var response = new DomainResponse<BooleanResult>();
            if (IsDuplicatedEmail(admin.Email, admin.AdminId))
            {
                return response.ReturnFailResponse(new[] { "This email address is already existed on the system. Please choose another one." }
                       , "This email address is already existed on the system. Please choose another one."
                       , new BooleanResult { Success = false });
            }

            try
            {
                var adminData = _uOW.AdminRepo.GetByID(admin.AdminId);
                adminData.FirstName = admin.FirstName;
                adminData.LastName = admin.LastName;
                adminData.Email = admin.Email;
                _uOW.AdminRepo.Update(adminData);
                _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.");
        }
Ejemplo n.º 9
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.");
        }
Ejemplo n.º 10
0
        public DomainResponse<IEnumerable<Place>> GetStateList()
        {
            var response = new DomainResponse<IEnumerable<Place>>();
            try
            {
                response.Result = _uOW.PlaceRepo.Get(filter: p => p.PlaceTypeId == StateTypeId).ToArray();
            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to retrieve data", null);
            }

            return response.ReturnSuccessResponse(response.Result, null, null);
        }
Ejemplo n.º 11
0
        public DomainResponse<Place> GetPlaceWithChildPlacesById(int id)
        {
            var response = new DomainResponse<Place>();
            try
            {
                response.Result = _uOW.PlaceRepo.Get(x => x.PlaceId == id, null, "StateChilds,AttractionChilds,TownCityChilds").FirstOrDefault();

            }
            catch (Exception ex)
            {
                return response.ReturnFailResponse(new[] { ex.Message }
                       , "There is an error trying to retrieve data", null);
            }

            if (response.Result != null)
                return response.ReturnSuccessResponse(response.Result, null, null);
            else
                return response.ReturnFailResponse(new[] { string.Format("Error occur whilte retrieving data for admingId {0}", id) }
                    , "There is an error trying to retrieve data", null);
        }