Exemplo n.º 1
0
        public async Task <int> EditQueenAsync(
            int queenId,
            DateTime fertilizationDate,
            DateTime givingDate,
            QueenType queenType,
            string origin,
            string hygenicHabits,
            string temperament,
            QueenColor queenColor,
            QueenBreed queenBreed)
        {
            var queen = this.queenRepository
                        .All()
                        .FirstOrDefault(q => q.Id == queenId);

            queen.FertilizationDate = fertilizationDate;
            queen.GivingDate        = givingDate;
            queen.QueenType         = queenType;
            queen.Origin            = origin;
            queen.HygenicHabits     = hygenicHabits;
            queen.Temperament       = temperament;
            queen.Color             = queenColor;
            queen.Breed             = queenBreed;

            await this.queenRepository.SaveChangesAsync();

            return(queen.BeehiveId);
        }
Exemplo n.º 2
0
        public async Task <int> CreateUserQueenAsync(
            string creatorId,
            string ownerId,
            int beehiveId,
            DateTime fertilizationDate,
            DateTime givingDate,
            QueenType queenType,
            string origin,
            string hygenicHabits,
            string temperament,
            QueenColor queenColor,
            QueenBreed queenBreed)
        {
            var queen = new Queen
            {
                CreatorId         = creatorId,
                OwnerId           = ownerId,
                BeehiveId         = beehiveId,
                Breed             = queenBreed,
                Color             = queenColor,
                FertilizationDate = fertilizationDate,
                GivingDate        = givingDate,
                HygenicHabits     = hygenicHabits,
                Origin            = origin,
                QueenType         = queenType,
                Temperament       = temperament,
            };

            await this.queenRepository.AddAsync(queen);

            await this.queenRepository.SaveChangesAsync();

            var beehive = this.beehiveRepository
                          .All()
                          .Where(b => b.Id == beehiveId)
                          .FirstOrDefault();

            beehive.QueenId = queen.Id;
            await this.queenRepository.SaveChangesAsync();

            var apiaryId = this.beehiveRepository
                           .All()
                           .Where(b => b.Id == beehiveId)
                           .Select(b => b.ApiaryId)
                           .FirstOrDefault();

            var allApiaryHelpersIds = this.apiaryHelperRepository
                                      .All()
                                      .Where(x => x.ApiaryId == apiaryId)
                                      .Select(x => x.UserId);

            foreach (var helperId in allApiaryHelpersIds)
            {
                var helper = new QueenHelper
                {
                    UserId  = helperId,
                    QueenId = queen.Id,
                };

                await this.queenHelperRepository.AddAsync(helper);
            }

            await this.queenHelperRepository.SaveChangesAsync();

            return(queen.BeehiveId);
        }