Exemple #1
0
        public AddVoteResponse AddVote(AddVoteRequest request)
        {
            AddVoteResponse response = new AddVoteResponse();
            try
            {
                Vote vote = new Vote()
                {
                    ProductId = request.ProductId,
                    UserId = request.UserId,
                    VoteDate = DateTime.Now
                };

                votesRepository.Add(vote);
                unitOfWork.Commit();
                response.Status = true;
                response.Message = "ok";
            }
            catch (Exception e)
            {
                response.Status = false;
                response.Message = e.Message;
                if (e.InnerException != null)
                {
                    response.Message += Environment.NewLine;
                    response.Message += string.Format("Inner exception: {0}", e.InnerException.Message);
                }
            }

            return response;
        }
Exemple #2
0
        public static List<ProductViewModel> ProductListToProductViewModelList(List<Product> products, int userId, Vote vote)
        {
            List<ProductViewModel> prods = new List<ProductViewModel>();

            int votedProductId = 0;
            if (vote != null)
            {
               votedProductId  = vote.ProductId;
            }

            foreach (var item in products)
            {
                ProductViewModel prod = new ProductViewModel();
                prod.Id = item.Id;
                prod.Name = item.Name;
                prod.Description = item.Description;
                prod.ImagePath = item.ImagePath;
                prod.VotesAmount = (item.Votes != null) ? item.Votes.Count() : 0;
                prod.ButtonClass = (item.Id == votedProductId) ? EnumDescription.GetEnumDescription(ButtonClass.Voted) : EnumDescription.GetEnumDescription(ButtonClass.Default);
                prod.EditActionLink = "/Home/Edit/" + item.Id;
                prods.Add(prod);
            }

            return prods;
        }