Ejemplo n.º 1
0
        private PerformanceEntity AddPerformanceEntity(IPerformanceData data, int locationId, int typeId)
        {
            try
            {
                LocationsEntity location = locationId != -1
                    ? _dbContext.PerformanceLocations.FirstOrDefault(l => l.Id == locationId)
                    : new LocationsEntity {
                    Name = data.Location
                };

                PerformanceTypeEntity type = typeId != -1
                    ? _dbContext.PerformanceTypes.FirstOrDefault(t => t.Id == typeId)
                    : new PerformanceTypeEntity {
                    TypeName = data.Type
                };

                PerformanceEntity performance = new PerformanceEntity
                {
                    Name     = data.Name,
                    Location = location,
                    Type     = type,
                };

                _dbContext.Performances.Add(performance);

                return(performance);
            }
            catch (Exception e)
            {
                Console.WriteLine($"AddPerformanceEntity DbException: {e.Message}");
                throw;
            }
        }
Ejemplo n.º 2
0
        private int GetPerformanceEntityId(IPerformanceData data, out int locationId, out int typeId)
        {
            LocationsEntity l = _dbContext.PerformanceLocations.AsNoTracking()
                                .FirstOrDefault(x => x.Name == data.Location);

            locationId = l?.Id ?? -1;

            PerformanceTypeEntity t = _dbContext.PerformanceTypes.AsNoTracking().FirstOrDefault(x => x.TypeName == data.Type);

            typeId = t?.Id ?? -1;

            if (l == null || t == null)
            {
                return(-1);
            }

            var performanceId = _dbContext.Performances.AsNoTracking()
                                .FirstOrDefault(p => p.Location == l && p.Type == t && p.Name == data.Name)?.Id ?? -1;

            return(performanceId);
        }