Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public ActionResult Create(CreatDogVM model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var file = model.Photo;
             if (file != null)
             {
                 Dog dog = new Dog
                 {
                     Name    = model.Name,
                     Age     = model.Age,
                     Weight  = model.Weight,
                     Gender  = model.Gender,
                     Breed   = model.Breed,
                     AddDate = DateTime.Now
                 };
                 dogService.Insert(dog);
                 int id = dog.Id;
                 dog.PhotoPath = "/Images/Dogs/" + id + ".jpg";
                 file.SaveAs(Server.MapPath("/Images/Dogs/" + id + ".jpg"));
                 dogService.Update(dog);
                 ViewBag.Message = "Dog data added successfully.";
             }
             else
             {
                 ViewBag.Error = "Image not found!";
             }
         }
     }
     catch (Exception e)
     {
         ViewBag.Exception = e.InnerException.InnerException.Message;
         ViewBag.Error     = "Something went wrong!";
     }
     return(View(model));
 }