Пример #1
0
        public async Task <OperationDetails> Create(EventDTO modelDto)
        {
            var @event = new Event
            {
                Name        = modelDto.Name,
                CategoryId  = modelDto.CategoryId,
                Date        = modelDto.DateTime,
                Description = modelDto.Description,
                VenueId     = modelDto.VenueId,
                Banner      = ConvertImageToByte(modelDto)
            };

            var eventName     = _context.Events.FirstOrDefault(e => e.Name.Equals(@event.Name));
            var eventDataTime = _context.Events.FirstOrDefault(e => e.Date == @event.Date);
            var venueName     = _venueService.GetNameVenueById(@event.VenueId);
            var cityName      = _venueService.GetCityNameByVenueId(@event.VenueId);

            if (eventName == null || eventDataTime == null || venueName == null || cityName == null)
            {
                await _context.Events.AddAsync(@event);

                await _context.SaveChangesAsync();

                return(new OperationDetails(true, "The event is successfully created", string.Empty));
            }
            else
            {
                return(new OperationDetails(false, $"An event with the name {@event.Name} already exist", "Name"));
            }
        }