Exemple #1
0
        public HttpResponseMessage GetArticles(int order, int skip, int take)
        {
            // order 1: newest, 0: featurest
            try
            {
                List <ArticleExpandedModel> articles;
                if ((OrderType)order == OrderType.Feature)
                {
                    var articlesResult = _iArticleServices.GetArticles().OrderByDescending(c => c.view).Skip(skip).Take(take).ToList();
                    articles = Mapper.Map <List <ArticleEntity>, List <ArticleExpandedModel> >(articlesResult);
                    var pets        = _iPetServices.GetAll();
                    var petEntities = pets as IList <PetEntity> ?? pets.ToList();
                    foreach (var article in articles)
                    {
                        foreach (var pet in petEntities.Where(pet => article.petId == pet.id))
                        {
                            article.Pet = Mapper.Map <PetEntity, PetModel>(pet);
                            var userAuthInfo = _iUserAuthInfoServices.GetUserAuthInforById(pet.userAuthInfoId);
                            article.Pet.User = _iUserServices.GetUserById(userAuthInfo.userId);
                            var images = _iImageServices.GetAll();
                            foreach (var image in images.Where(image => article.Pet.imageId == image.id))
                            {
                                article.Pet.Image = image;
                            }
                        }
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, articles));
                }

                var newArticlesResult = _iArticleServices.GetArticles().OrderByDescending(c => c.view).Skip(skip).Take(take).ToList();
                articles = Mapper.Map <List <ArticleEntity>, List <ArticleExpandedModel> >(newArticlesResult);
                var newPets        = _iPetServices.GetAll();
                var newPetEntities = newPets as IList <PetEntity> ?? newPets.ToList();
                foreach (var article in articles)
                {
                    foreach (var pet in newPetEntities.Where(pet => article.petId == pet.id))
                    {
                        article.Pet = Mapper.Map <PetEntity, PetModel>(pet);
                        var userAuthInfo = _iUserAuthInfoServices.GetUserAuthInforById(pet.userAuthInfoId);
                        article.Pet.User = _iUserServices.GetUserById(userAuthInfo.userId);
                        var images = _iImageServices.GetAll();
                        foreach (var image in images.Where(image => article.Pet.imageId == image.id))
                        {
                            article.Pet.Image = image;
                        }
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, articles));
            }
            catch (Exception e)
            {
                return(ResponseHelper.ErrorResult(Request, HttpStatusCode.InternalServerError, ErrorMessages.ERROR_MSG_SERVER_ERROR, ErrorCodeStrings.SERVER_ERROR, e.ToString()));
            }
        }
Exemple #2
0
        // GET: Pet
        public ActionResult Index()
        {
            _logger.LogError("opa");
            var model = _petService.GetAll();

            return(View(model));
        }