コード例 #1
0
        public async Task <JsonResult> GetBrands()
        {
            try
            {
                logger.Debug("Search Controller GetBrands action method is invoked");

                BrandModel model = new BrandModel(_unitOfWork);

                List <Brand> records = await model.GetBrandsByPageAsync(null, null, string.Empty, string.Empty, string.Empty, string.Empty);

                return(this.Json(records.Select(x => new { Id = x.Id, Name = x.Name }), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                logger.Error("Error while invoking GetBrands action method: ", ex);
                return(this.Json(new { error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public async Task <JsonResult> ListAsync(int?page, int?limit, string sortBy, string direction, string code, string name)
        {
            try
            {
                BrandModel model = new BrandModel(_unitOfWork);

                List <Brand> records = await model.GetBrandsByPageAsync(page, limit, sortBy, direction, code, name);

                int total = await model.GetTotalBrandsAsync(page, limit, sortBy, direction, code, name);

                logger.Debug("Brand Controller List action method is invoked");
                logger.Debug(string.Format("Total {0} brands are found and {1} is returned", total, records.Count()));

                return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                logger.Error("Error while invoking List action method: ", ex);
                return(this.Json(new { error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }