Ejemplo n.º 1
0
        public virtual async Task <int> EditAsync(IServiceDetailsModel <TKey> serviceDetailsModel)
        {
            var model  = serviceDetailsModel.To <TEntity>();
            var entity = await this.deletableEntityRepository.GetByIdWithDeletedAsync(serviceDetailsModel.Id);

            var modelProperties  = model.GetType().GetProperties();
            var entityProperties = entity.GetType().GetProperties();

            foreach (var modelProperty in modelProperties)
            {
                foreach (var property in entityProperties)
                {
                    if (property.Name == modelProperty.Name &&
                        property.Name != "Id" &&
                        property.Name != "CreatedOn" &&
                        property.Name != "ModifiedOn")
                    {
                        property.SetValue(entity, modelProperty.GetValue(model));
                        break;
                    }
                }
            }

            this.deletableEntityRepository.Update(entity);
            var result = await this.deletableEntityRepository.SaveChangesAsync();

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <int> EditAsync(IServiceDetailsModel <TKey> serviceDetailsModel)
        {
            var entity = serviceDetailsModel.To <TEntity>();

            this.deletableEntityRepository.Update(entity);
            var result = await this.deletableEntityRepository.SaveChangesAsync();

            return(result);
        }
Ejemplo n.º 3
0
        public override async Task <int> EditAsync(IServiceDetailsModel <int> serviceDetailsModel)
        {
            var townFromDb = await this.townRepository.All()
                             .Where(t => t.Id == serviceDetailsModel.Id)
                             .Select(t => new Town()
            {
                CountryId = t.CountryId,
            })
                             .FirstOrDefaultAsync();

            var town = serviceDetailsModel.To <Town>();

            town.CountryId = townFromDb.CountryId;
            town.Parkings  = townFromDb.Parkings;

            this.townRepository.Update(town);
            var result = await this.townRepository.SaveChangesAsync();

            return(result);
        }
Ejemplo n.º 4
0
        public override async Task <int> EditAsync(IServiceDetailsModel <int> serviceDetailsModel)
        {
            var gameFromD = await this.gamesRepository.GetByIdAsync(serviceDetailsModel.Id);

            await this.SubtractTeamsData(gameFromD);

            var game = serviceDetailsModel.To <Game>();

            await this.gamesRepository.UpdateAsync(game);

            var result = await this.gamesRepository.SaveChangesAsync();

            var updatedGame = await this.gamesRepository.GetByIdAsync(serviceDetailsModel.Id);

            await this.UpdateTeamsData(updatedGame);

            await this.gamesRepository.SaveChangesAsync();

            return(result);
        }
Ejemplo n.º 5
0
        public override async Task <int> EditAsync(IServiceDetailsModel <int> serviceDetailsModel)
        {
            var parkingFromDb = await this.parkingRepository.All()
                                .Where(p => p.Id == serviceDetailsModel.Id)
                                .Select(p => new Parking
            {
                TownId           = p.TownId,
                Capacity         = p.Capacity,
                FreeParkingSlots = p.FreeParkingSlots,
                ParkingSlots     = p.ParkingSlots.Select(ps => new ParkingSlot()
                {
                    Id = ps.Id,
                })
                                   .ToList(),
                Cars = p.Cars.Select(c => new Car()
                {
                    Id = c.Id,
                })
                       .ToList(),
                Reservations = p.Reservations.Select(r => new Reservation()
                {
                    Id = r.Id,
                })
                               .ToList(),
            })
                                .FirstOrDefaultAsync();

            var parking = serviceDetailsModel.To <Parking>();

            parking.TownId           = parkingFromDb.TownId;
            parking.Capacity         = parkingFromDb.Capacity;
            parking.FreeParkingSlots = parkingFromDb.FreeParkingSlots;
            parking.ParkingSlots     = parkingFromDb.ParkingSlots;
            parking.Cars             = parkingFromDb.Cars;
            parking.Reservations     = parkingFromDb.Reservations;

            this.parkingRepository.Update(parking);
            var result = await this.parkingRepository.SaveChangesAsync();

            return(result);
        }