Exemplo n.º 1
0
        public void Add_ShouldSucceed_WithUnusedId(string ownerId, string petId, string firstName, string lastName)
        {
            //Arrange
            Guid wrongGuid = Guid.Parse("c3b922ac-a2bf-4b75-a9dc-5b3c44798264");
            Guid ownerGuid = Guid.Parse(ownerId);

            _mockOwnerRepository.Setup(x => x.GetByIdAsync(ownerGuid))
            .ReturnsAsync((tblOwner)null);

            tblOwner owner = new tblOwner()
            {
                Id = ownerGuid, FirstName = firstName, LastName = lastName
            };
            //Act
            var result = _service.Add(owner);

            //Assert
            _mockOwnerRepository.Verify(x => x.GetByIdAsync(ownerGuid), Times.Once());
            Assert.True(result.IsCompletedSuccessfully);
        }
Exemplo n.º 2
0
        public ActionResult Add(OwnerAddRequest model)
        {
            ActionResult result = null;

            try
            {
                int id = _service.Add(model);

                result = Created201(id);
            }
            catch (Exception ex)
            {
                result = StatusCode(500, ex.ToString());
            }

            return(result);
        }
Exemplo n.º 3
0
            public async Task <BaseResponses <AddPost> > Handle(CreatePostRequest request, CancellationToken cancellationToken)
            {
                BaseResponses <AddPost> responses = null;

                using (var trx = unitOfWork.BeginTransaction())
                {
                    try
                    {
                        var mapData = mapper.Map <AddPost>(request);
                        var data    = await addressService.Add(mapData);

                        responses = new BaseResponses <AddPost>(data);
                        unitOfWork.SaveChanges();
                    }
                    catch (RestException ex)
                    {
                        trx.Rollback();
                        responses = new BaseResponses <AddPost>(ex.StatusCode, ex.Message);
                    }
                    return(responses);
                }
            }
Exemplo n.º 4
0
        public async Task <ActionResult <tblOwner> > PostOwner([FromBody] OwnerVM owner)
        {
            //Validate model
            if (owner == null)
            {
                return(BadRequest("No data provided."));
            }

            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var createdOwner = await _ownerService.Add(new tblOwner
            {
                FirstName = owner.FirstName,
                LastName  = owner.LastName
            });

            owner.OwnerId = createdOwner.Id;
            return(Ok(owner));
        }
Exemplo n.º 5
0
 public IActionResult AddEditOwner([FromBody] Owners model)
 {
     try
     {
         if (model.Id == 0)
         {
             _owner.Add(model);
             _owner.Save();
             return(_jsonResponse.GenerateJsonResult(1, "Owner save Successfully"));
         }
         var edit = _owner.GetSingle(x => x.Id == model.Id);
         edit.first_name = model.first_name;
         edit.last_name  = model.last_name;
         _owner.Update(edit);
         _owner.Save();
         return(_jsonResponse.GenerateJsonResult(1, "Owner update Successfully"));
     }
     catch (Exception ex)
     {
         return(_jsonResponse.GenerateJsonResult(0, "UnhandledError"));
     }
 }
Exemplo n.º 6
0
        public ActionResult Create(OwnerViewModel ownerViewModel)
        {
            if (ModelState.IsValid)
            {
                var model = mapperService.Map <OwnerViewModel, OwnerDTO>(ownerViewModel);
                try
                {
                    dbService.Add(model);

                    //dbService.Owners.Add(owner);
                    //db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View("Create"));
                }
            }
            else
            {
                return(View("Create"));
            }
        }
 public ActionResult AddOwner(Owner owner)
 {
     return(Json(ownerService.Add(owner)));
 }