Пример #1
0
        public IActionResult GetCustomers([FromQuery] CustomerListParameters resourceParameters)
        {
            if (resourceParameters.Page < 1)
            {
                resourceParameters.Page = 1; //0 is default when not specified
            }

            if (resourceParameters.Take == 0)
            {
                resourceParameters.Take = 50; //default when value is not specified.
            }
            else if (resourceParameters.Take > 250)
            {
                _logger.LogError("Get Customers max items exceeded.");
                return(new ValidationFailedResult("A request can only take maximum of 250 items."));
            }

            var customers = _customerData.Get(0, resourceParameters);

            var pagination = new PaginationModel
            {
                Previous = CreateCustomersResourceUri(resourceParameters, -1),
                Next     = CreateCustomersResourceUri(resourceParameters, 1),
                Take     = resourceParameters.Take,
                Page     = resourceParameters.Page
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pagination));


            var models = customers.Select(c => new CustomerDisplayViewModel(c));

            return(Ok(models));
        }
Пример #2
0
        public IActionResult Details(int id)
        {
            var customer = _customerData.Get(id);

            if (customer == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public ActionResult Details(int id)
        {
            Customer model = db.Get(id);

            if (model == null)
            {
                return(View(ViewNameNotFound));
            }
            return(View(model));
        }
Пример #4
0
        public IActionResult Edit(int id)
        {
            var model = _customerdata.Get(id);

            if (model == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        [HttpGet("{id}")] //  ./api/customers/:id
        public IActionResult Get(int id)
        {
            var customer = _customerData.Get(id);

            if (customer == null)
            {
                return(NotFound());
            }
            var model = new CustomerDisplayViewModel(customer);

            return(Ok(model));
        }
        private void Construtor(Employee employee, ICustomerData customerData, IEnumerable <Status> statuses, Order order)
        {
            Status status = statuses.FirstOrDefault(s => s.Id == order.StatusId);

            OrderId      = order.Id;
            EmployeeName = employee.Name;
            CustomerName = customerData.Get(order.CustomerId).Name;
            StartDate    = order.StartDate;
            EndDate      = order.EndDate.GetValueOrDefault();
            Description  = order.Description;
            Status       = status.StatusDescription;
            StatusColour = status.StatusColour;
            HoursWorked  = order.HoursWorked;
        }