示例#1
0
        private UIElement Add(IEnumerable <string> sports, IEnumerable <TournamentBaseModel> tournaments, IEnumerable <ParticipantTournamentModel> participants)
        {
            EventCreateViewModel viewModel = new EventCreateViewModel(sports, tournaments, participants);
            EventCreateControl   control   = new EventCreateControl(viewModel);

            viewModel.EventCreated += (s, e) =>
            {
                EventCreateModel eventCreateModel = e.Event;
                EventCreateDTO   eventCreateDTO   = Mapper.Map <EventCreateModel, EventCreateDTO>(eventCreateModel);

                using (IEventService service = factory.CreateEventService())
                {
                    ServiceMessage serviceMessage = service.CreateWithParticipants(eventCreateDTO);
                    RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

                    if (serviceMessage.IsSuccessful)
                    {
                        viewModel.Notes = String.Empty;
                        Notify();
                    }
                }
            };

            return(control);
        }
示例#2
0
        public EventCreateDTO GetEventCreateDTO()
        {
            var eventCreate = new EventCreateDTO
            {
                Event           = new EventCreationDTO {
                },
                Сommandant      = new EventAdministrationDTO {
                },
                Alternate       = new EventAdministrationDTO {
                },
                Bunchuzhnyi     = new EventAdministrationDTO {
                },
                Pysar           = new EventAdministrationDTO {
                },
                EventCategories = new List <EventCategoryDTO>
                {
                    new EventCategoryDTO {
                    }
                },
                EventTypes = new List <EventTypeDTO>
                {
                    new EventTypeDTO {
                    }
                },
                Users = new List <UserInfoDTO>
                {
                    new UserInfoDTO {
                    }
                }
            };

            return(eventCreate);
        }
示例#3
0
        public ActionResult <EventReadDTO> CreateEvent(EventCreateDTO eventCreateDto)
        {
            Event eventModel = _mapper.Map <Event>(eventCreateDto);

            _repository.Events.CreateEvent(eventModel);
            List <InterestsEvent> interests = new List <InterestsEvent>();

            _repository.Save();

            foreach (var interest in eventCreateDto.Interests)
            {
                interests.Add(new InterestsEvent()
                {
                    EventId = eventModel.EventId, InterestId = interest.InterestId
                });
            }
            eventModel.InterestsEvents = interests;
            eventModel.Organizers      = new List <Organizer>();
            foreach (var org in eventCreateDto.Organizers)
            {
                eventModel.Organizers.Add(new Organizer
                {
                    EventId         = eventModel.EventId,
                    TelephoneNumber = org.TelephoneNumber
                });
            }
            _repository.Save();


            EventReadDTO eventReadDto = _mapper.Map <EventReadDTO>(eventModel);

            return(CreatedAtRoute(nameof(GetEventById), new { id = eventReadDto.EventId }, eventReadDto));
        }
示例#4
0
        public async Task <ActionResult <EventDTO> > CreateEvent(EventCreateDTO eventCreateDTO)
        {
            var Event = _mapper.Map <Event>(eventCreateDTO);
            await _events.CreateEvent(Event);

            return(Ok(Event));
        }
示例#5
0
        public async Task <bool> CreateEvent(EventCreateDTO dto)
        {
            var rao = _mapper.Map <EventCreateRAO>(dto);

            if (await _repository.CreateEvent(rao))
            {
                return(true);
            }

            throw new NotImplementedException();
        }
        public async Task <ActionResult> CreateEvent([FromBody] EventCreateDTO @event)
        {
            // validate data
            var _event = _mapper.Map <Event>(@event);

            if (@event.CategoryId != null)
            {
                _event.Category = await _context.Categories.FindAsync(@event.CategoryId);

                if (_event.Category == null)
                {
                    return(BadRequest(new
                    {
                        error = $"The category with id: {@event.CategoryId} don't exists"
                    }));
                }
            }

            _event.Status = await _context.EventStatuses.FindAsync(@event.StatusId);

            if (_event.Status == null)
            {
                return(BadRequest(new
                {
                    error = $"The status with id: {@event.StatusId} don't exists"
                }));
            }

            if (@event.TagsId != null)
            {
                foreach (var tagId in @event.TagsId)
                {
                    var tag = await _context.Tags.FindAsync(tagId);

                    if (tag == null)
                    {
                        return(BadRequest(new
                        {
                            error = $"The tag with id: {tagId} don't exists"
                        }));
                    }
                    _event.Tags.Add(new EventTag
                    {
                        Tag   = tag,
                        Event = _event
                    });
                }
            }

            _event.CreatedAt  = DateTime.UtcNow;
            _event.ModifiedAt = DateTime.UtcNow;

            return(CreatedAtAction(nameof(CreateEvent), new { id = _event.Id }));
        }
示例#7
0
        public ActionResult <EventReadDTO> CreateEvent(EventCreateDTO eventCreateDTO)
        {
            var eventModel = _mapper.Map <Event>(eventCreateDTO);

            _eventService.CreateEvent(eventModel);
            _eventService.SaveChanges();

            var eventReadDto = _mapper.Map <EventReadDTO>(eventModel);

            return(CreatedAtRoute(nameof(GetEventById), new { Id = eventReadDto.EventId }, eventReadDto));
        }
        public void Create(EventCreateDTO currentEvent)
        {
            this.context.Events.Add(new Event()
            {
                Name           = currentEvent.Name,
                Place          = currentEvent.Place,
                Start          = currentEvent.Start,
                End            = currentEvent.End,
                PricePerTicket = currentEvent.PricePerTicket,
                TotalTickets   = currentEvent.TotalTickets
            });

            this.context.SaveChanges();
        }
示例#9
0
        public async Task <int> CreateEventAsync(EventCreateDTO model)
        {
            model.Event.EventStatusID = await _eventStatusManager.GetStatusIdAsync("Не затверджені");

            var eventToCreate    = _mapper.Map <EventCreationDTO, Event>(model.Event);
            var commandantTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Комендант");

            var alternateTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Заступник коменданта");

            var bunchuzhnyiTypeID = await _eventAdministrationTypeManager.GetTypeIdAsync("Бунчужний");

            var pysarTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Писар");

            var administrationList = new List <EventAdministration>
            {
                new EventAdministration
                {
                    UserID = model.Сommandant.UserId,
                    EventAdministrationTypeID = commandantTypeId,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Alternate.UserId,
                    EventAdministrationTypeID = alternateTypeId,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Bunchuzhnyi.UserId,
                    EventAdministrationTypeID = bunchuzhnyiTypeID,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Pysar.UserId,
                    EventAdministrationTypeID = pysarTypeId,
                    EventID = eventToCreate.ID,
                },
            };

            eventToCreate.EventAdministrations = administrationList;

            await _repoWrapper.Event.CreateAsync(eventToCreate);

            await _repoWrapper.SaveAsync();

            return(eventToCreate.ID);
        }
示例#10
0
        public async Task <EventCreateDTO> InitializeEventCreateDTOAsync()
        {
            var eventCategories = await _eventCategoryManager.GetDTOAsync();

            var users      = _mapper.Map <List <User>, IEnumerable <UserInfoDTO> >((await _repoWrapper.User.GetAllAsync()).ToList());
            var eventTypes = _mapper.Map <List <EventType>, IEnumerable <EventTypeDTO> >((await _repoWrapper.EventType.GetAllAsync()).ToList());

            var model = new EventCreateDTO()
            {
                Users           = users,
                EventTypes      = eventTypes,
                EventCategories = eventCategories
            };

            return(model);
        }
示例#11
0
        public async Task EditEventAsync(EventCreateDTO model)
        {
            await GetAdministrationTypeId();

            model.Event.EventStatusID = await eventStatusManager.GetStatusIdAsync("Не затверджені");

            var eventToEdit = mapper.Map <EventCreationDTO, Event>(model.Event);

            eventToEdit.EventAdministrations = new List <EventAdministration>
            {
                new EventAdministration
                {
                    UserID = model.Сommandant.UserId,
                    EventAdministrationTypeID = commandantTypeId,
                    EventID = eventToEdit.ID,
                    ID      = (await repoWrapper.EventAdministration.GetFirstAsync(predicate: i => i.EventAdministrationTypeID == commandantTypeId &&
                                                                                   i.EventID == eventToEdit.ID, include: source => source.Include(q => q.User))).ID
                },
                new EventAdministration
                {
                    UserID = model.Alternate.UserId,
                    EventAdministrationTypeID = alternateTypeId,
                    EventID = eventToEdit.ID,
                    ID      = (await repoWrapper.EventAdministration.GetFirstAsync(predicate: i => i.EventAdministrationTypeID == alternateTypeId &&
                                                                                   i.EventID == eventToEdit.ID, include: source => source.Include(q => q.User))).ID
                },
                new EventAdministration
                {
                    UserID = model.Bunchuzhnyi.UserId,
                    EventAdministrationTypeID = bunchuzhnyiTypeID,
                    EventID = eventToEdit.ID,
                    ID      = (await repoWrapper.EventAdministration.GetFirstAsync(predicate: i => i.EventAdministrationTypeID == bunchuzhnyiTypeID &&
                                                                                   i.EventID == eventToEdit.ID, include: source => source.Include(q => q.User))).ID
                },
                new EventAdministration
                {
                    UserID = model.Pysar.UserId,
                    EventAdministrationTypeID = pysarTypeId,
                    EventID = eventToEdit.ID,
                    ID      = (await repoWrapper.EventAdministration.GetFirstAsync(predicate: i => i.EventAdministrationTypeID == pysarTypeId &&
                                                                                   i.EventID == eventToEdit.ID, include: source => source.Include(q => q.User))).ID
                }
            };
            repoWrapper.Event.Update(eventToEdit);
            await repoWrapper.SaveAsync();
        }
示例#12
0
        public async Task <int> CreateEventAsync(EventCreateDTO model)
        {
            await GetAdministrationTypeId();

            model.Event.EventStatusID = await eventStatusManager.GetStatusIdAsync("Не затверджені");

            var eventToCreate = mapper.Map <EventCreationDTO, Event>(model.Event);

            var administrationList = new List <EventAdministration>
            {
                new EventAdministration
                {
                    UserID = model.Сommandant.UserId,
                    EventAdministrationTypeID = commandantTypeId,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Alternate.UserId,
                    EventAdministrationTypeID = alternateTypeId,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Bunchuzhnyi.UserId,
                    EventAdministrationTypeID = bunchuzhnyiTypeID,
                    EventID = eventToCreate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Pysar.UserId,
                    EventAdministrationTypeID = pysarTypeId,
                    EventID = eventToCreate.ID,
                },
            };

            eventToCreate.EventAdministrations = administrationList;

            await repoWrapper.Event.CreateAsync(eventToCreate);

            await repoWrapper.SaveAsync();

            return(eventToCreate.ID);
        }
示例#13
0
        public async Task <EventCreateDTO> InitializeEventEditDTOAsync(int eventId)
        {
            var editedEvent = await _repoWrapper.Event.GetFirstAsync(predicate : i => i.ID == eventId, include : source => source.Include(i => i.EventAdministrations));

            var users           = _mapper.Map <List <User>, IEnumerable <UserInfoDTO> >((await _repoWrapper.User.GetAllAsync()).ToList());
            var eventTypes      = _mapper.Map <List <EventType>, IEnumerable <EventTypeDTO> >((await _repoWrapper.EventType.GetAllAsync()).ToList());
            var eventCategories = await _eventCategoryManager.GetDTOAsync();

            var commandantTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Комендант");

            var alternateTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Заступник коменданта");

            var bunchuzhnyiTypeID = await _eventAdministrationTypeManager.GetTypeIdAsync("Бунчужний");

            var pysarTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Писар");

            var commandant = _mapper.Map <EventAdministration, EventAdministrationDTO>(await _repoWrapper.EventAdministration.
                                                                                       GetFirstAsync(predicate: i => i.EventAdministrationTypeID == commandantTypeId && i.EventID == eventId, include: source => source.Include(q => q.User)));
            var alternate = _mapper.Map <EventAdministration, EventAdministrationDTO>(await _repoWrapper.EventAdministration.
                                                                                      GetFirstAsync(predicate: i => i.EventAdministrationTypeID == alternateTypeId && i.EventID == eventId, include: source => source.Include(q => q.User)));
            var bunchuzhnyi = _mapper.Map <EventAdministration, EventAdministrationDTO>(await _repoWrapper.EventAdministration.
                                                                                        GetFirstAsync(predicate: i => i.EventAdministrationTypeID == bunchuzhnyiTypeID && i.EventID == eventId, include: source => source.Include(q => q.User)));
            var pysar = _mapper.Map <EventAdministration, EventAdministrationDTO>(await _repoWrapper.EventAdministration.
                                                                                  GetFirstAsync(predicate: i => i.EventAdministrationTypeID == pysarTypeId && i.EventID == eventId, include: source => source.Include(q => q.User)));
            var model = new EventCreateDTO()
            {
                Event           = _mapper.Map <Event, EventCreationDTO>(editedEvent),
                Users           = users,
                EventTypes      = eventTypes,
                EventCategories = eventCategories,
                Сommandant      = commandant,
                Alternate       = alternate,
                Bunchuzhnyi     = bunchuzhnyi,
                Pysar           = pysar
            };

            return(model);
        }
示例#14
0
        public async Task EditEventAsyncTest_UpdatesAndSavesRepo()
        {
            //Arrange
            _eventStatusManager
            .Setup(x => x.GetStatusIdAsync(It.IsAny <string>()))
            .ReturnsAsync(1);
            _mapper
            .Setup(x => x.Map <EventCreationDTO, DAEvent>(It.IsAny <EventCreationDTO>()))
            .Returns(new DAEvent()
            {
                EventAdministrations = new List <EventAdministration>(), ID = 0
            });
            _repoWrapper
            .Setup(x => x.EventAdministration.GetFirstAsync(
                       It.IsAny <Expression <Func <EventAdministration, bool> > >(),
                       It.IsAny <Func <IQueryable <EventAdministration>, IIncludableQueryable <EventAdministration, object> > >()))
            .ReturnsAsync(new EventAdministration()
            {
                ID = 1
            });
            _repoWrapper
            .Setup(x => x.Event.Update(It.IsAny <DAEvent>()));
            var inputModel = new EventCreateDTO();

            inputModel.Event       = new EventCreationDTO();
            inputModel.Сommandant  = new EventAdministrationDTO();
            inputModel.Alternate   = new EventAdministrationDTO();
            inputModel.Bunchuzhnyi = new EventAdministrationDTO();
            inputModel.Pysar       = new EventAdministrationDTO();

            //Act
            await _service.EditEventAsync(inputModel);

            //Assert
            _repoWrapper.Verify(x => x.Event.Update(It.IsAny <DAEvent>()));
            _repoWrapper.Verify(x => x.SaveAsync());
        }
示例#15
0
        public async Task <IActionResult> EventEdit([FromBody] EventCreateDTO createDTO)
        {
            await _eventUserManager.EditEventAsync((createDTO));

            return(NoContent());
        }
示例#16
0
        public async Task <IActionResult> EventCreate([FromBody] EventCreateDTO createDTO)
        {
            createDTO.Event.ID = await _eventUserManager.CreateEventAsync(createDTO);

            return(Created(nameof(GetEventUserByUserId), createDTO));
        }
 public ServiceMessage CreateWithParticipants(EventCreateDTO eventCreateDTO)
 {
     return(new ServiceMessage("No permisssions", false));
 }
示例#18
0
        //TODO rewrite
        public ServiceMessage CreateWithParticipants(EventCreateDTO eventCreateDTO)
        {
            string message = "";
            bool   success = true;

            string   sportName             = eventCreateDTO.SportName;
            string   tournamentName        = eventCreateDTO.TournamentName;
            DateTime dateOfTournamentStart = eventCreateDTO.DateOfTournamentStart;

            string   notes       = eventCreateDTO.Notes;
            DateTime dateOfEvent = eventCreateDTO.DateOfEvent;
            List <ParticipantBaseDTO> participants = eventCreateDTO.Participants;


            if (eventCreateDTO.DateOfEvent >= DateTime.Now)
            {
                if (participants != null && participants.Count > 1)
                {
                    if (success = Validate(eventCreateDTO, ref message))
                    {
                        try
                        {
                            TournamentEntity tournamentEntity = unitOfWork.Tournaments.Get(tournamentName, sportName, dateOfTournamentStart);
                            if (tournamentEntity != null)
                            {
                                if (dateOfEvent.Date >= dateOfTournamentStart.Date)
                                {
                                    bool isDualSport = tournamentEntity.Sport.IsDual;
                                    if (isDualSport)
                                    {
                                        if (participants.Count == 2)
                                        {
                                            IEnumerable <ParticipantEntity> participantEntities = participants
                                                                                                  .Select(p => unitOfWork.Participants.Get(p.Name, p.SportName, p.CountryName));

                                            bool isAnyParticipantBusy = participantEntities.Any(p => unitOfWork.Participants.IsBusyOn(p.Id, dateOfEvent));

                                            if (!isAnyParticipantBusy)
                                            {
                                                EventEntity eventEntity = new EventEntity
                                                {
                                                    DateOfEvent  = dateOfEvent,
                                                    Notes        = notes,
                                                    TournamentId = tournamentEntity.Id
                                                };

                                                IEnumerable <ParticipationEntity> participations = participantEntities
                                                                                                   .Select(p =>
                                                {
                                                    return(new ParticipationEntity
                                                    {
                                                        Event = eventEntity,
                                                        Participant = p
                                                    });
                                                });

                                                foreach (var participation in participations)
                                                {
                                                    unitOfWork.Participations.Add(participation);
                                                }
                                                unitOfWork.Commit();

                                                message = String.Format("Created new event with {0} participants", participants.Count);
                                            }
                                            else
                                            {
                                                message = "Some participants cannot play on this date";
                                                success = false;
                                            }
                                        }
                                        else
                                        {
                                            message = "Sport is dual. Only two participants can take part";
                                            success = false;
                                        }
                                    }
                                    else
                                    {
                                        IEnumerable <ParticipantEntity> participantEntities = participants
                                                                                              .Select(p => unitOfWork.Participants.Get(p.Name, p.SportName, p.CountryName));

                                        bool isAnyParticipantBusy = participantEntities.Any(p => unitOfWork.Participants.IsBusyOn(p.Id, dateOfEvent));

                                        if (!isAnyParticipantBusy)
                                        {
                                            EventEntity eventEntity = new EventEntity
                                            {
                                                DateOfEvent  = dateOfEvent,
                                                Notes        = notes,
                                                TournamentId = tournamentEntity.Id
                                            };

                                            IEnumerable <ParticipationEntity> participations = participantEntities
                                                                                               .Select(p =>
                                            {
                                                return(new ParticipationEntity
                                                {
                                                    Event = eventEntity,
                                                    Participant = p
                                                });
                                            });

                                            foreach (var participation in participations)
                                            {
                                                unitOfWork.Participations.Add(participation);
                                            }
                                            unitOfWork.Commit();

                                            message = String.Format("Created new event with {0} participants", participants.Count);
                                        }
                                        else
                                        {
                                            message = "Some participants cannot play on this date";
                                            success = false;
                                        }
                                    }
                                }
                                else
                                {
                                    message = "An event cannot start earlier then tournament";
                                    success = false;
                                }
                            }
                            else
                            {
                                message = "Such tournament was not found";
                                success = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            message = ExceptionMessageBuilder.BuildMessage(ex);
                            success = false;
                        }
                    }
                }
                else
                {
                    message = "Invalid count of participants";
                    success = false;
                }
            }
            else
            {
                message = "Invalid date: cannot start event in the past";
                success = false;
            }

            return(new ServiceMessage(message, success));
        }
示例#19
0
        public async Task EditEventAsync(EventCreateDTO model)
        {
            model.Event.EventStatusID = await _eventStatusManager.GetStatusIdAsync("Не затверджені");

            var eventToEdit      = _mapper.Map <EventCreationDTO, Event>(model.Event);
            var commandantTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Комендант");

            var alternateTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Заступник коменданта");

            var bunchuzhnyiTypeID = await _eventAdministrationTypeManager.GetTypeIdAsync("Бунчужний");

            var pysarTypeId = await _eventAdministrationTypeManager.GetTypeIdAsync("Писар");

            var commandant = await _repoWrapper.EventAdministration.
                             GetFirstAsync(predicate : i => i.EventAdministrationTypeID == commandantTypeId && i.EventID == eventToEdit.ID, include : source => source.Include(q => q.User));

            var alternate = await _repoWrapper.EventAdministration.
                            GetFirstAsync(predicate : i => i.EventAdministrationTypeID == alternateTypeId && i.EventID == eventToEdit.ID, include : source => source.Include(q => q.User));

            var bunchuzhnyi = await _repoWrapper.EventAdministration.
                              GetFirstAsync(predicate : i => i.EventAdministrationTypeID == bunchuzhnyiTypeID && i.EventID == eventToEdit.ID, include : source => source.Include(q => q.User));

            var pysar = await _repoWrapper.EventAdministration.
                        GetFirstAsync(predicate : i => i.EventAdministrationTypeID == pysarTypeId && i.EventID == eventToEdit.ID, include : source => source.Include(q => q.User));

            var administrationList = new List <EventAdministration>
            {
                new EventAdministration
                {
                    UserID = model.Сommandant.UserId,
                    EventAdministrationTypeID = commandantTypeId,
                    EventID = eventToEdit.ID,
                    ID      = commandant.ID,
                },
                new EventAdministration
                {
                    UserID = model.Alternate.UserId,
                    EventAdministrationTypeID = alternateTypeId,
                    EventID = eventToEdit.ID,
                    ID      = alternate.ID,
                },
                new EventAdministration
                {
                    UserID = model.Bunchuzhnyi.UserId,
                    EventAdministrationTypeID = bunchuzhnyiTypeID,
                    EventID = eventToEdit.ID,
                    ID      = bunchuzhnyi.ID,
                },
                new EventAdministration
                {
                    UserID = model.Pysar.UserId,
                    EventAdministrationTypeID = pysarTypeId,
                    EventID = eventToEdit.ID,
                    ID      = pysar.ID,
                },
            };

            eventToEdit.EventAdministrations = administrationList;
            _repoWrapper.Event.Update(eventToEdit);
            await _repoWrapper.SaveAsync();
        }