Пример #1
0
        public void UpdateRepair_DateCompletedIsBeforeDateOpenedReturnsBadRequest()
        {
            RepairData repair = new RepairData
            {
                Customer = 1
            };

            var createdRepair = _fixItTrackerRepository.AddRepair(repair.Repair);

            var jsonPatchDocument  = new JsonPatchDocument <RepairPatchData>();
            var jsonPatchOperation = new Operation <RepairPatchData>("replace", "DateCompleted", null, createdRepair.DateOpened.AddYears(-1).ToShortDateString());

            jsonPatchDocument.Operations.Add(jsonPatchOperation);

            var badResponse = _repairController.UpdateRepair(createdRepair.RepairID, jsonPatchDocument);

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Пример #2
0
        public ActionResult CreateRepair([FromBody] RepairData repairData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer customer = _dataContext.GetCustomer(repairData.Customer);

            if (customer == null)
            {
                return(BadRequest("Customer doesn't exist"));
            }

            Repair repair = repairData.Repair;

            repair.Customer = customer;

            var createdRepair = _dataContext.AddRepair(repair);

            var uri = Request != null?Request.GetDisplayUrl().ToString() + createdRepair.RepairID : "";

            return(Created(uri, "Repair Created"));
        }