Example #1
0
        /// <summary>
        /// Create a venue. A venue can not be created without layouts
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task Create(VenueDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (!IsNameUnique(entity, true))
            {
                throw new VenueException("Such venue already exists");
            }

            if (entity.LayoutList == null || !entity.LayoutList.Any())
            {
                throw new VenueException("Incorrect state of the venue. The venue must have at least one layout");
            }

            var venueAdd = VenueParser.MapToVenue(entity);

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                _context.VenueRepository.Create(venueAdd);
                await _context.SaveAsync();

                entity.Id = venueAdd.Id;
                foreach (var layout in entity.LayoutList)
                {
                    layout.VenueId = venueAdd.Id;
                    await _layoutService.Create(layout);
                }

                transaction.Complete();
            }
        }
Example #2
0
        public async Task Update(LayoutDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (entity.VenueId <= 0)
            {
                throw new LayoutException("VenueId is invalid");
            }

            if (!IsDescriptionUnique(entity, false))
            {
                throw new LayoutException("Area description isn't unique");
            }

            if (entity.AreaList == null || !entity.AreaList.Any())
            {
                throw new LayoutException("Incorrect state of the layout. The layout must have at least one area");
            }

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                var update = await _context.LayoutRepository.GetAsync(entity.Id);

                update.VenueId     = entity.VenueId;
                update.Description = entity.Description;
                _context.LayoutRepository.Update(update);
                await _context.SaveAsync();

                var existingAreas = await _context.AreaRepository.FindByAsync(x => x.LayoutId == entity.Id);

                //find and remove layouts which were deleted
                existingAreas.Where(list2 => entity.AreaList.All(list1 => list1.Id != list2.Id)).ToList()
                .ForEach(x =>
                {
                    _context.AreaRepository.Delete(x);
                });

                foreach (var area in entity.AreaList)
                {
                    if (area.Id == 0)
                    {
                        area.LayoutId = update.Id;
                        await _areaService.Create(area);
                    }
                    else
                    {
                        await _areaService.Update(area);
                    }
                }

                transaction.Complete();
            }
        }
Example #3
0
        public async Task Update(VenueDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (!IsNameUnique(entity, false))
            {
                throw new VenueException("Such venue already exists");
            }

            if (entity.LayoutList == null || !entity.LayoutList.Any())
            {
                throw new VenueException("Incorrect state of the venue. The venue must have at least one layout");
            }

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                var update = await _context.VenueRepository.GetAsync(entity.Id);

                update.Name        = entity.Name;
                update.Phone       = entity.Phone;
                update.Description = entity.Description;
                update.Address     = entity.Address;
                update.Timezone    = entity.Timezone;
                _context.VenueRepository.Update(update);
                await _context.SaveAsync();

                var existingLayouts = await _context.LayoutRepository.FindByAsync(x => x.VenueId == entity.Id);

                //find and remove layouts which were deleted
                existingLayouts.Where(list2 => entity.LayoutList.All(list1 => list1.Id != list2.Id)).ToList()
                .ForEach(x =>
                {
                    _context.LayoutRepository.Delete(x);
                });

                foreach (var layout in entity.LayoutList)
                {
                    if (layout.Id == 0)
                    {
                        layout.VenueId = update.Id;
                        await _layoutService.Create(layout);
                    }
                    else
                    {
                        await _layoutService.Update(layout);
                    }
                }

                transaction.Complete();
            }
        }
Example #4
0
        public async Task Update(AreaDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (entity.LayoutId <= 0)
            {
                throw new AreaException("LayoutId is invalid");
            }

            if (!IsDescriptionUnique(entity, false))
            {
                throw new AreaException("Area description isn't unique");
            }

            if (entity.SeatList == null || !entity.SeatList.Any())
            {
                throw new AreaException("Incorrect state of area. An area must have atleast one seat");
            }

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                var delete = await _context.AreaRepository.GetAsync(entity.Id);

                _context.AreaRepository.Delete(delete);
                var createNew = AreaParser.MapToArea(entity);
                _context.AreaRepository.Create(createNew);
                await _context.SaveAsync();

                foreach (var seat in entity.SeatList)
                {
                    seat.AreaId = createNew.Id;

                    if (!IsSeatUnique(seat, false))
                    {
                        throw new SeatException("Seat already exists");
                    }

                    var seatAdd = SeatParser.MapToSeat(seat);
                    _context.SeatRepository.Create(seatAdd);
                }
                await _context.SaveAsync();

                transaction.Complete();
            }
        }
Example #5
0
        /// <summary>
        /// Create a layout. A layout can not be created without areas
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task Create(LayoutDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (entity.VenueId <= 0)
            {
                throw new LayoutException("VenueId is invalid");
            }

            if (!IsDescriptionUnique(entity, true))
            {
                throw new LayoutException("Layout description isn't unique");
            }

            if (entity.AreaList == null || !entity.AreaList.Any())
            {
                throw new LayoutException("Incorrect state of the layout. The layout must have at least one area");
            }

            var layoutAdd = LayoutParser.MapToLayout(entity);

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                _context.LayoutRepository.Create(layoutAdd);
                await _context.SaveAsync();

                entity.Id = layoutAdd.Id;
                foreach (var area in entity.AreaList)
                {
                    area.LayoutId = layoutAdd.Id;
                    await _areaService.Create(area);
                }

                transaction.Complete();
            }
        }