示例#1
0
 public ActionResult <DogDTO> Put([FromBody] DogForUpdateDTO model)
 {
     try
     {
         var            dog             = mapper.Map <Dog>(model);
         TrainingCourse trainingCourse  = trainingCourseService.GetBy(t => t.Name == model.TrainingCourse);
         Dog            dogFromDatabase = dogService.GetById(model.Id);
         if (dogFromDatabase == null)
         {
             return(NotFound());
         }
         dogFromDatabase.Breed            = dog.Breed;
         dogFromDatabase.Name             = dog.Name;
         dogFromDatabase.TaskEngagements  = dog.TaskEngagements;
         dogFromDatabase.TrainingCourseId = dog.TrainingCourseId;
         dogFromDatabase.DateOfBirth      = dogFromDatabase.DateOfBirth;
         dogFromDatabase.ChipNumber       = dog.ChipNumber;
         dogFromDatabase.TrainingCourseId = trainingCourse.TrainingCourseId;
         dogService.Update(dogFromDatabase);
         DogDTO dogDTO = mapper.Map <DogDTO>(dogFromDatabase);
         //    return Created($"api/dogs/get/{dogDTO.Name}", dogDTO);
         return(Ok(dogDTO));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#2
0
        public async Task AddDogAsync(DogDTO addDogDTO, string userId)
        {
            var newDog = mapper.Map <DogDTO, Dog>(addDogDTO);

            newDog.UserId = userId;
            await applicationContext.AddAsync(newDog);

            await applicationContext.SaveChangesAsync();
        }
示例#3
0
        public async Task EditDogAsync(DogDTO editDogDTO, long dogId)
        {
            var dogToEdit = await FindDogById(dogId);

            if (dogToEdit != null)
            {
                var editedDog = mapper.Map(editDogDTO, dogToEdit);
                applicationContext.Dogs.Update(editedDog);
                await applicationContext.SaveChangesAsync();
            }
        }
    public static DogDTO CreateFrom(Dog dog)
    {
        if (dog == null)
        {
            return(null);
        }
        DogDTO dto = new DogDTO();

        dto.Name     = dog.Name;
        dto.Birthday = dog.Birthday;
    }
        public async Task <ActionResult> EditDog([FromRoute] long dogId, [FromBody] DogDTO dogDTO)
        {
            if (ModelState.IsValid)
            {
                await dogService.EditDogAsync(dogDTO, dogId);

                return(Ok());
            }

            return(BadRequest());
        }
        public async Task <ActionResult> AddDog([FromRoute] string userId, [FromBody] DogDTO dogDTO)
        {
            if (ModelState.IsValid)
            {
                await dogService.AddDogAsync(dogDTO, userId);

                return(Ok());
            }

            return(BadRequest());
        }
示例#7
0
 public async Task Post(DogDTO dog)
 {
     try
     {
         if (String.IsNullOrEmpty(dog.Name))
         {
             return;
         }
         await _service.Add(dog);
     }catch (Exception ex)
     {
         var d = ex.Message;
     }
 }
    public static Dog ToDog(DogDTO dto)
    {
        // if the data transfer object is null
        // we cannot make a Dog from it.
        if (dto == null)
        {
            return(null);
        }
        Dog dog = new Dog();

        // We can be sure of what these values are intended to be.
        dog.Name     = dto.Name;
        dog.Birthday = dto.Birthday;
        return(dog);
    }
示例#9
0
        public ActionResult <DogDTO> Post([FromBody] DogForCreationDTO model)
        {
            var            dog            = mapper.Map <Dog>(model);
            TrainingCourse trainingCourse = trainingCourseService.GetBy(t => t.Name == model.TrainingCourse);
            Dog            dogToInsert    = new Dog()
            {
                Breed          = dog.Breed,
                ChipNumber     = dog.ChipNumber,
                DateOfBirth    = dog.DateOfBirth,
                Gender         = dog.Gender,
                Name           = dog.Gender,
                TrainingCourse = trainingCourse
            };

            dogService.Insert(dog);
            DogDTO dogDTO = mapper.Map <DogDTO>(dog);

            return(Ok(dogDTO));
            //  return Created($"api/dogs/get/{dogDTO.Name}", dogDTO);
        }
示例#10
0
 public async Task Add(DogDTO dog)
 {
     await _repository.Add(_mapper.mapper.Map <Dog>(dog));
 }