Example #1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] TypeOfOperationViewModel typeOfOperation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != typeOfOperation.TypeOfOperationId)
            {
                return(BadRequest());
            }
            try
            {
                await _repository.Update(typeOfOperation);

                return(CreatedAtAction("Get", new { id = typeOfOperation.TypeOfOperationId }, typeOfOperation));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TypeOfOperationExists(id))
                {
                    return(NotFound());
                }
                throw;
            }
        }
        public async Task Update(TypeOfOperationViewModel typeOfOperation)
        {
            var c = new TypeOfOperation
            {
                TypeOfOperationId = typeOfOperation.TypeOfOperationId,
                Name     = typeOfOperation.Name,
                IsActive = typeOfOperation.IsActive
            };

            _db.TypeOfOperations.Update(c);
            await _db.SaveChangesAsync();
        }
Example #3
0
        public async Task Put_ReturnsBadRequestIfSuppliedIdNotLikeViewModel()
        {
            _mockRepositoryTypeOfOperation.Setup(x => x.GetAll()).ReturnsAsync(_typeOfOperations);

            var firstTypeOfOperation = _typeOfOperations[0];
            var viewModel            = new TypeOfOperationViewModel {
                Name = firstTypeOfOperation.Name, IsActive = firstTypeOfOperation.IsActive
            };

            viewModel.Name = "Foo Flight";
            _typeOfOperationController.ModelState.AddModelError("test", "test");
            var result = await _typeOfOperationController.Put(99999, viewModel);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(BadRequestObjectResult));
        }
Example #4
0
        public async Task Put_ReturnsTypeOfOperationOnSuccess()
        {
            _mockRepositoryTypeOfOperation.Setup(x => x.GetAll()).ReturnsAsync(_typeOfOperations);

            var firstTypeOfOperation = _typeOfOperations[0];
            var viewModel            = new TypeOfOperationViewModel
            {
                Name = firstTypeOfOperation.Name, IsActive = firstTypeOfOperation.IsActive
            };

            viewModel.Name = "Foo Flight";
            var result = await _typeOfOperationController.Put(viewModel.TypeOfOperationId, viewModel);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(CreatedAtActionResult));
            Assert.AreEqual(viewModel, (result as CreatedAtActionResult)?.Value);
        }