示例#1
0
        public JsonResult AddNewCustomer(CustomerModel customer)
        {
            if (customer.Name.Length > 255)
                return Json(new {Result = "Fail", Message = "Name is too long."});

            try
            {
                _customerService.AddNewCustomer(customer.Name);
            }
            catch (Exception e)
            {
                return Json(new {Result = "Fail", e.Message});
            }

            return Json(new {Result = "Success"});
        }
示例#2
0
        public JsonResult GetCustomers(JQueryDataTablesModel datatablesRequestInfo, CustomerModel customer)
        {
            var random = new Random();
            IList<Customer> customers = _customerService.GetCustomers().Where(x => x.Name.StartsWith(datatablesRequestInfo.sSearch_[0])).ToList();
            IEnumerable<CustomersGridResponseModel> customerDtos =
                   customers.Select(x => new CustomersGridResponseModel
                   {
                       CustomerId = x.Id,
                       CreationDate = x.Created.LocalDateTime,
                       CustomerName = x.Name,
                       Calls = random.Next(),
                       Fields = random.Next(),
                       Details = random.Next().ToString()
                   });

            var customersGridResponseModels = customerDtos as IList<CustomersGridResponseModel> ?? customerDtos.ToList();
            IEnumerable<CustomersGridResponseModel> dtos =
                customersGridResponseModels.Skip(datatablesRequestInfo.iDisplayStart)
                                           .Take(datatablesRequestInfo.iDisplayLength);
            var numberOfcustomersToShow = customersGridResponseModels.Count();
            var response = new JQueryDataTablesResponse<CustomersGridResponseModel>(dtos, numberOfcustomersToShow, numberOfcustomersToShow,
                                                                                    datatablesRequestInfo.sEcho);
            return Json(response);
        }