public ActionResult SuggestWords(SuggestionRequestModel suggestionRequest)
        {
            var suggestions = new SuggestionsModel();

            suggestions.Moves = FindMoves(suggestionRequest.Board.Board, suggestionRequest.Hand.Hand, suggestionRequest.Board.List)
                                .Take(20).ToImmutableList();
            suggestionRequest.Suggestions = suggestions;

            return(View("Index", suggestionRequest));
        }
Example #2
0
        public SuggestionsModel getSuggestionList(SuggestionsViewModel foRequest)
        {
            if (foRequest.inPageSize <= 0)
            {
                foRequest.inPageSize = 10;
            }

            if (foRequest.inPageIndex <= 0)
            {
                foRequest.inPageIndex = 1;
            }

            if (foRequest.stSortColumn == "")
            {
                foRequest.stSortColumn = null;
            }

            if (foRequest.stSearch == "")
            {
                foRequest.stSearch = null;
            }


            List <Expression <Func <Suggestions, Object> > > includes        = new List <Expression <Func <Suggestions, object> > >();
            Expression <Func <Suggestions, object> >         IncludeProducts = (product) => product.Products;
            Expression <Func <Suggestions, object> >         IncludeUser     = (suggestion) => suggestion.AspNetUsers;

            includes.Add(IncludeProducts);
            includes.Add(IncludeUser);

            Func <IQueryable <Suggestions>, IOrderedQueryable <Suggestions> > orderingFunc =
                query => query.OrderBy(x => x.Id);

            Expression <Func <Suggestions, bool> > expression = null;

            //expression = x => x.IsDeleted == false;

            if (!string.IsNullOrEmpty(foRequest.stSortColumn))
            {
                switch (foRequest.stSortColumn)
                {
                case "ID DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.Id);
                    break;

                case "ProductName DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.ProductId);
                    break;

                case "ProductName ASC":
                    orderingFunc = q => q.OrderBy(s => s.ProductId);
                    break;

                case "UserName DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.Name);
                    break;

                case "UserName ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.Name);
                    break;

                case "UserEmail DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.Email);
                    break;

                case "UserEmail ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.Email);
                    break;

                case "UserContact DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.PhoneNumber);
                    break;

                case "UserContact ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.PhoneNumber);
                    break;

                case "Suggestion DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.Suggestion);
                    break;

                case "Suggestion ASC":
                    orderingFunc = q => q.OrderBy(s => s.Suggestion);
                    break;
                }
            }
            (List <Suggestions>, int)objSuggestions = Repository <Suggestions> .GetEntityListForQuery(expression, orderingFunc, includes, foRequest.inPageIndex, foRequest.inPageSize);

            SuggestionsModel objSuggestion = new SuggestionsModel();

            objSuggestion.inRecordCount = objSuggestions.Item2;
            objSuggestion.inPageIndex   = foRequest.inPageIndex;
            objSuggestion.Pager         = new Pager(objSuggestions.Item2, foRequest.inPageIndex);

            if (objSuggestions.Item1.Count > 0)
            {
                foreach (var suggestion in objSuggestions.Item1)
                {
                    objSuggestion.loSuggestionList.Add(new SuggestionsViewModel
                    {
                        Id                = suggestion.Id,
                        ProductName       = suggestion.Products.Name,
                        UserName          = suggestion.AspNetUsers.Name,
                        Email             = suggestion.AspNetUsers.Email,
                        UserContectNumber = suggestion.AspNetUsers.PhoneNumber,
                        Suggestion        = suggestion.Suggestion,
                        IsReplied         = suggestion.IsReplied,
                        ProductImgPath    = getProductImgPath(suggestion.ProductId)
                    });
                }
            }

            return(objSuggestion);
        }
Example #3
0
        public ActionResult searchSuggestions(SuggestionsViewModel foSearchRequest)
        {
            SuggestionsModel loSuggestionModel = getSuggestionList(foSearchRequest);

            return(PartialView("~/Areas/Admin/Views/Suggestion/_Suggestions.cshtml", loSuggestionModel));
        }
        public async Task <IActionResult> GetAll(int offset = 0, int limit = 100)
        {
            long totalCount = 0;
            var  totalPages = 0;
            var  routeName  = "GetAllSuggestions";

            var pagedList = await suggestionApp.GetAllAsync(offset, limit);

            if (pagedList.IsNotNull() && pagedList.Items.IsNotNull() && pagedList.Items.Count > 0)
            {
                totalCount = pagedList.Total;
                totalPages = (int)Math.Ceiling((double)totalCount / limit);
            }

            var urlHelper = urlHelperFactory.GetUrlHelper(ControllerContext);

            var prevLink = offset > 0 ? urlHelper.Link(routeName, new { offset = limit > offset ? 0 : offset - limit, limit = limit }) : string.Empty;
            var nextLink = offset < totalCount - limit ? urlHelper.Link(routeName, new { offset = offset + limit, limit = limit }) : string.Empty;

            var firstLink = offset > 0 ? urlHelper.Link(routeName, new { offset = 0, limit = limit }) : string.Empty;
            var lastLink  = offset < totalCount - limit ? urlHelper.Link(routeName, new { offset = totalCount - limit, limit = limit }) : string.Empty;

            var links = new List <Link>();

            if (prevLink.HasValue())
            {
                links.Add(new Link {
                    Href = prevLink, Method = Method.GET, Relation = "previous"
                });
            }

            if (nextLink.HasValue())
            {
                links.Add(new Link {
                    Href = nextLink, Method = Method.GET, Relation = "next"
                });
            }

            if (firstLink.HasValue())
            {
                links.Add(new Link {
                    Href = firstLink, Method = Method.GET, Relation = "first"
                });
            }

            if (lastLink.HasValue())
            {
                links.Add(new Link {
                    Href = lastLink, Method = Method.GET, Relation = "last"
                });
            }

            var result = new SuggestionsModel
            {
                TotalCount = pagedList.Total,
                TotalPages = totalPages,
                Links      = links,
                Items      = pagedList.Items.Select(e => SuggestionModel.ToModel(e)).ToArray()
            };

            return(Ok(result));
        }