Ejemplo n.º 1
0
        public async Task <Trullo> GetTrulloById([Service] ITrulloRepository trulloRepository, [Service] ITopicEventSender eventSender, string id)
        {
            Trullo trulloResult = trulloRepository.GetTrulloById(id);
            await eventSender.SendAsync("ReturnedTrullo", trulloResult);

            return(trulloResult);
        }
Ejemplo n.º 2
0
        public async Task <Trullo> Create(Trullo trullo)
        {
            await _db.AddAsync(trullo);

            await _db.SaveChangesAsync();

            return(trullo);
        }
Ejemplo n.º 3
0
        public Trullo DeleteTrullo(DeleteTrulloInput deletedTrullo)
        {
            Trullo oldTrullo = new Trullo
            {
                Id = deletedTrullo.Id
            };

            return(_trulloRepository.Delete(oldTrullo));
        }
Ejemplo n.º 4
0
            public async Task <Property> GetPropertyAsync(
                Trullo trullo,
                PropertyDataLoader dataLoader,
                CancellationToken cancellationToken)
            {
                var data = await dataLoader.LoadAsync(new string[] { trullo.Property_id }, cancellationToken);

                return(data.FirstOrDefault());
            }
Ejemplo n.º 5
0
        public async Task <Trullo> CreateTrullo([Service] ITrulloRepository trulloRepository, [Service] ITopicEventSender eventSender, CreateTrulloInput trullo)
        {
            Trullo newTrullo = new Trullo
            {
                //Id = _trulloRepository.GetAll().Max(x => x.Id) + 1,
                Name        = trullo.Name,
                Description = trullo.Description,
                Capacity    = trullo.Capacity,
                Price       = trullo.Price,
                PropertyId  = trullo.PropertyId
            };

            var createdTrullo = await trulloRepository.Create(newTrullo);

            await eventSender.SendAsync("TrulloCreated", createdTrullo);

            return(createdTrullo);
        }
Ejemplo n.º 6
0
        public Trullo Delete(Trullo trullo)
        {
            var trulloToDelete = GetAll().FirstOrDefault(t => t.Id == trullo.Id);

            if (trulloToDelete == null)
            {
                throw new TrulloNotFound()
                      {
                          TrulloId = trullo.Id
                      }
            }
            ;

            _db.Remove(trulloToDelete);
            _db.SaveChanges();

            return(trulloToDelete);
        }
Ejemplo n.º 7
0
        public async Task <Trullo> CreateTrullo([Service] ITrulloRepository trulloRepository, [Service] ITopicEventSender eventSender, CreateTrulloInput trullo)
        {
            Trullo newTrullo = new Trullo
            {
                _id         = ObjectId.GenerateNewId().ToString(),
                Name        = trullo.Name,
                Description = trullo.Description,
                Capacity    = trullo.Capacity,
                Price       = trullo.Price,
                Property_id = trullo.PropertyId
            };

            var createdTrullo = await trulloRepository.Create(newTrullo);

            await eventSender.SendAsync("TrulloCreated", createdTrullo);

            return(createdTrullo);
        }
        public Trullo Delete(Trullo trullo)
        {
            //var trulloToDelete = GetAll().FirstOrDefault(t => t.Trullo_id == trullo.Trullo_id);
            //if (trulloToDelete == null)
            //    throw new TrulloNotFound() { TrulloId = trullo.Trullo_id };

            //_db.Trulli.FindOneAndDelete(trulloToDelete);

            var filter = new BsonDocument("FirstName", "Jack");

            var result = _db.Trulli.FindOneAndDelete(filter);

            if (result == null)
            {
                throw new TrulloNotFound()
                      {
                          TrulloId = trullo._id
                      };
            }

            return(result);
        }
        public async Task <Trullo> Create(Trullo trullo)
        {
            await _db.Trulli.InsertOneAsync(trullo);

            return(trullo);
        }