public void UpsertIntakeFamily_NoOrder_ReturnNotFound()
        {
            var   orderId = "1";
            Order order   = null;

            _mockRepository.Setup(r => r.GetOrderFor(_userId, orderId, UserRoles.Consultant)).Returns(order);

            var dto = new OrdersTransfereeIntakeFamilyDto()
            {
                Id = orderId, SpouseName = "Test Name"
            };

            var result = _controller.UpsertIntakeFamily(dto) as IHttpActionResult;

            result.Should().BeOfType <System.Web.Http.Results.NotFoundResult>();
        }
Ejemplo n.º 2
0
        public IHttpActionResult UpsertIntakeFamily(OrdersTransfereeIntakeFamilyDto dto)
        {
            var   userId = User.Identity.GetUserId();
            Order order  = _unitOfWork.Orders.GetOrderFor(userId, dto.Id, User.GetUserRole());

            if (order == null)
            {
                return(NotFound());
            }

            foreach (var childDto in dto.Children)
            {
                var child = order.Children.FirstOrDefault(c => !String.IsNullOrEmpty(childDto.Id) && c.Id == childDto.Id);
                if (child == null)
                {
                    child    = _mapper.Map <ChildDto, Child>(childDto);
                    child.Id = Guid.NewGuid().ToString();
                    order.Children.Add(child);
                }
                else
                {
                    _mapper.Map <ChildDto, Child>(childDto, child);
                }
            }

            foreach (var petDto in dto.Pets)
            {
                var pet = order.Pets.FirstOrDefault(p => !String.IsNullOrEmpty(petDto.Id) && p.Id == petDto.Id);
                if (pet == null)
                {
                    pet    = _mapper.Map <PetDto, Pet>(petDto);
                    pet.Id = Guid.NewGuid().ToString();
                    order.Pets.Add(pet);
                }
                else
                {
                    _mapper.Map <PetDto, Pet>(petDto, pet);
                }
            }

            _mapper.Map <OrdersTransfereeIntakeFamilyDto, Order>(dto, order);
            _unitOfWork.Complete();

            //On success, return the newly created id's with the associated temp id's so that the client can be updated.
            return(Ok());
        }