コード例 #1
0
        public static bool DeletePlace([ActivityTrigger] int placeId)
        {
            var request = new PlaceIdRequest()
            {
                Id = placeId
            };

            return(_client.PlacesClient.DeletePlace(request));
        }
コード例 #2
0
        /// <summary>
        ///  Gets a place by Id
        /// </summary>
        /// <param name="request">Place Id</param>
        /// <returns>Returns an individual Place</returns>
        ///
        public Place GetPlace(PlaceIdRequest request)
        {
            Place place    = null;
            var   response = GetAsync($"places/{request.Id}").Result;

            if (!response.IsSuccessStatusCode)
            {
                return(place);
            }

            var responseDate = response.Content.ReadAsStringAsync().Result;

            place = JsonConvert.DeserializeObject <Place>(responseDate);
            return(place);
        }
コード例 #3
0
        public static bool DeletePlace([ActivityTrigger] int placeId)
        {
            log.Information($"Calling DeletePlace function for Place with Id: {placeId}");
            try
            {
                var request = new PlaceIdRequest()
                {
                    Id = placeId
                };

                return(client.PlacesClient.DeletePlace(request));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                return(false);
            }
        }
コード例 #4
0
        public static Place GetPlace([ActivityTrigger] int placeId)
        {
            log.Information($"Calling GetPlace function with palceId : {placeId}");
            try
            {
                var request = new PlaceIdRequest()
                {
                    Id = placeId
                };

                return(client.PlacesClient.GetPlace(request));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                return(null);
            }
        }
コード例 #5
0
 public PlaceResponse GetPlace(PlaceIdRequest request)
 {
     using (var db = new EventSourceDbContext(_contextOptions))
     {
         var place = db.Places.Find(request.Id);
         if (place != null)
         {
             return(new PlaceResponse()
             {
                 Place = place
             });
         }
         return(new PlaceResponse()
         {
             Place = place, Result = false
         });
     }
 }
コード例 #6
0
        public Response DeletePlace(PlaceIdRequest request)
        {
            var response = new Response();

            using (var db = new EventSourceDbContext(_contextOptions))
            {
                var _place = db.Places.Find(request.Id);

                if (_place == null)
                {
                    response.Result = false;
                    return(response);
                }
                db.Places.Remove(_place);
                db.SaveChanges();
                return(response);
            }
        }
コード例 #7
0
        public PlaceResponse GetPlace(PlaceIdRequest request)
        {
            var response  = new PlaceResponse();
            var validator = new Response();

            try
            {
                validator = new PlaceIdRequestValidator(_placeRepository).Validate(request).ToResponse();
            }
            catch (Exception ex)
            {
                _logger.Error(ExceptionMessages.GetPlaceException, ex);
                response.Result = false;
                response.Errors.Add(new ResponseError {
                    Name = "GetPlaceException", Error = ExceptionMessages.GetPlaceException
                });
                return(response);
            }

            if (!validator.Result)
            {
                return new PlaceResponse()
                       {
                           Errors = validator.Errors
                       }
            }
            ;

            try
            {
                response = _placeRepository.GetPlace(request);
            }
            catch (Exception ex)
            {
                _logger.Error(ExceptionMessages.GetPlaceException, ex);
                response.Result = false;
                response.Errors.Add(new ResponseError {
                    Name = "GetPlaceException", Error = ExceptionMessages.GetPlaceException
                });
                return(response);
            }

            return(response);
        }
コード例 #8
0
        public IActionResult Get(int id)
        {
            var request = new PlaceIdRequest {
                Id = id
            };

            _logger.Information(LoggingMessages.GettingPlaceById(id));

            var response = _placeServices.GetPlace(request);

            if (!response.Result)
            {
                return(BadRequest(response.Errors));
            }

            if (response.Place == null)
            {
                return(NotFound("Place Not Found."));
            }

            return(Ok(response.Place));
        }
コード例 #9
0
        public IActionResult Delete(int id)
        {
            _logger.Information($"Deleting place with id: {id}");
            var request = new PlaceIdRequest()
            {
                Id = id
            };

            var response = _placeServices.DeletePlace(request);

            if (!response.Result)
            {
                return(BadRequest(response.Errors));
            }

            if (response.Errors.Count > 0)
            {
                return(NotFound(response.Errors));
            }

            return(Ok());
        }
コード例 #10
0
        /// <summary>
        ///  Deletes an individual Place
        /// </summary>
        /// <param name="request"> Place Id </param>
        /// <returns> Returns true or false </returns>
        public bool DeletePlace(PlaceIdRequest request)
        {
            var response = DeleteAsync($"places/{request.Id}").Result;

            return(response.IsSuccessStatusCode);
        }