Пример #1
0
        public async Task <Unit> Handle(PlaceCreatedEvent @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"---- Received {nameof(PlaceCreatedEvent)} message: Place.Guid = [{@event.Guid}] ----");

            var place = await _placeRepository.GetByGuid(@event.Guid);

            if (place != null)
            {
                _logger.LogInformation($"---- Place with Guid = [{@event.Guid}] already exists. Skipping event ----");
                return(await Task.FromResult(Unit.Value));
            }

            var user = await _userRepository.GetByGuid(@event.UserGuid);

            place = _placeMappingService.Map(@event, user.Id);
            if (@event.ParentPlaceGuid != null)
            {
                var parentPlace = await _placeRepository.GetByGuid((Guid)@event.ParentPlaceGuid);

                place.ParentLocationId = parentPlace.Id;
            }

            _placeRepository.Add(place);
            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Saved {nameof(PlaceCreatedEvent)} message: Place.Guid = [{@event.Guid}] Place.Id = [{place.Id}]----");

            return(await Task.FromResult(Unit.Value));
        }
Пример #2
0
 /// <summary>
 /// Save User Location
 /// </summary>
 /// <param name="place">the Location of the User</param>
 /// <param name="userId">The User Id</param>
 /// <returns>Place Object</returns>
 public Place SaveUserLocation(Place place, string userId)
 {
     if (_PlaceRepository.Get(place.PlaceId) == null)
     {
         _PlaceRepository.Add(place);
     }
     if (!String.IsNullOrEmpty(userId))
     {
         _UserRepository.SaveUserLocation(userId, place);
     }
     return(place);
 }
Пример #3
0
        public async Task <IActionResult> PostAsync(PlaceModel place)
        {
            var modelStateErrors = ModelStateErrors();

            Places places = _mapper.Map <Places>(place);

            _placeRepository.Add(places);

            await _unitOfWork.SaveChangesAsync();

            return(Ok(places));
        }
Пример #4
0
        public async Task <Place> AddPlaceAsync(Place place)
        {
            Place placeAdded;

            try
            {
                placeAdded = await _placeRepository.Add(place);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(placeAdded);
        }
Пример #5
0
        public IActionResult Post([FromBody] Place place)
        {
            if (place == null)
            {
                return(BadRequest());
            }

            var entity = Place.Create(place.Name, place.Rating, place.Address, place.Latitude, place.Longitude,
                                      place.OpenNow);

            _repository.Add(entity);
            _repository.SaveChanges();

            return(Ok(place));
        }
Пример #6
0
        public async Task <int> CreatePlace(CreatePlaceDto createPlaceDto)
        {
            _logger.LogInformation("{class}.{method} with dto = [{@dto}] Invoked", nameof(PlaceCommandService), nameof(CreatePlace), createPlaceDto);

            var userGuid = _httpContextUserService.GetUserGuid();
            var user     = await _userRepository.GetByGuid(userGuid);

            var place = _placeMappingService.Map(createPlaceDto, user);

            _placeRepository.Add(place);
            await _unitOfWork.Commit();

            _logger.LogInformation("{entityName} with id = [{id}] has been created in local database", nameof(Place), place.Id);

            var @event = _placeMappingService.MapToPlaceCreatedEvent(place);

            _eventBusPublisher.Publish(@event);

            _logger.LogInformation("{entityName} with id = [{id}] has been successfully created", nameof(Place), place.Id);

            return(place.Id);
        }
Пример #7
0
        public IActionResult AddPlace(Place place)
        {
            var places = _placeRepository.GetAll();

            foreach (var item in places)
            {
                if (item.Name == place.Name)
                {
                    ModelState.AddModelError("PlaceExist", "Already this Place is exist.");
                    break;
                }
            }

            if (ModelState.IsValid)
            {
                _placeRepository.Add(new Place()
                {
                    Name = place.Name
                });
                return(RedirectToAction("List"));
            }

            return(View(place));
        }
Пример #8
0
 public void AddPlace(Place item)
 {
     _placeRep.Add(item);
 }
Пример #9
0
 public void Add(CreatePlaceViewModel obj)
 {
     _placeRepository.Add(_mapper.Map <Place>(obj));
     _placeRepository.UnitOfWork.Commit();
 }
Пример #10
0
 public void CreatePlace(Place Place)
 {
     PlaceRepository.Add(Place);
     SavePlace();
 }
Пример #11
0
 public void CreatePlace(PlaceModel place)
 {
     _placeRepository.Add(_mapper.Map <Place>(place));
 }
Пример #12
0
 public void Add(Place dPlaces)
 {
     _placeRepository.Add(dPlaces);
 }
Пример #13
0
 public void AddPlace(Place place)
 {
     placeRepository.Add(place);
 }