コード例 #1
0
        public async Task <JsonResult> Get(int pageIndex, int pageSize, string pageOrder, int?productID, string friendEmail, string message)
        {
            var list = ProductSuggestions.Get(pageIndex,
                                              pageSize,
                                              pageOrder,
                                              productID,
                                              friendEmail,
                                              message);

            foreach (var item in list)
            {
                item.UserName = item.UserID != null
                                 ? (await UserManager.FindByIdAsync(item.UserID)).UserName
                                 : "******";
            }

            int total     = ProductSuggestions.Count(productID, friendEmail, message);
            int totalPage = (int)Math.Ceiling((decimal)total / pageSize);

            if (pageSize > total)
            {
                pageSize = total;
            }

            if (list.Count < pageSize)
            {
                pageSize = list.Count;
            }

            JsonResult result = new JsonResult()
            {
                Data = new
                {
                    TotalPages = totalPage,
                    PageIndex  = pageIndex,
                    PageSize   = pageSize,
                    Rows       = list
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }
コード例 #2
0
        public JsonResult Delete(int id)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                ProductSuggestions.Delete(id);
                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }