public ActionResult <LocationResponseDTO> Post([FromBody] LocationRequestDTO value)
 {
     try
     {
         var transmission = _insertLocation.Execute(value);
         return(Created("api/transmissions/" + transmission.Id, transmission));
     }
     catch (EntityExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error"));
     }
 }
 public IActionResult Put(int id, [FromBody] LocationRequestDTO value)
 {
     try
     {
         _updateLocation.Execute(id, value);
         return(NoContent());
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (EntityExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error"));
     }
 }
Ejemplo n.º 3
0
        public LocationResponseDTO Execute(LocationRequestDTO request)
        {
            var location         = new Location();
            var existingLocation = AiContext.Locations
                                   .Where(x => x.Adress == request.Adress)
                                   .Where(x => x.IsDeleted == 0)
                                   .FirstOrDefault();

            if (existingLocation != null)
            {
                throw new EntityExistsException("Location");
            }
            location.Adress = request.Adress;
            location.Price  = request.Price;
            AiContext.Add(location);
            AiContext.SaveChanges();
            return(new LocationResponseDTO
            {
                Id = location.Id,
                Adress = location.Adress,
                Price = location.Price
            });
        }
        public void Execute(int search, LocationRequestDTO request)
        {
            var location = AiContext.Locations
                           .Find(search);

            if (location == null || location.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Location");
            }
            var existingLocation = AiContext.Locations
                                   .Where(x => x.Adress == request.Adress)
                                   .Where(x => x.IsDeleted == 0)
                                   .Where(x => x.Id != location.Id)
                                   .FirstOrDefault();

            if (existingLocation != null)
            {
                throw new EntityExistsException("Location");
            }
            location.Adress     = request.Adress;
            location.Price      = request.Price;
            location.ModifiedAt = DateTime.UtcNow;
            AiContext.SaveChanges();
        }