Ejemplo n.º 1
0
        private async Task <Event> MapNewEvent(CreateEventDto newEventDto)
        {
            var newEvent = new Event
            {
                Created        = DateTime.UtcNow,
                CreatedBy      = newEventDto.UserId,
                OrganizationId = newEventDto.OrganizationId,
                OfficeIds      = JsonConvert.DeserializeObject <string[]>(newEventDto.Offices.Value),
                IsPinned       = newEventDto.IsPinned
            };

            var newWall = new CreateWallDto
            {
                Name          = newEventDto.Name,
                Logo          = newEventDto.ImageName,
                Access        = WallAccess.Private,
                Type          = WallType.Events,
                ModeratorsIds = new List <string> {
                    newEventDto.ResponsibleUserId
                },
                MembersIds = new List <string> {
                    newEventDto.ResponsibleUserId
                },
                UserId         = newEventDto.UserId,
                OrganizationId = newEventDto.OrganizationId
            };

            var wallId = await _wallService.CreateNewWallAsync(newWall);

            newEvent.WallId = wallId;
            UpdateEventInfo(newEventDto, newEvent);

            return(newEvent);
        }
Ejemplo n.º 2
0
        private void MapNewOptions(CreateEventDto newEventDto, Event newEvent)
        {
            if (newEventDto.NewOptions == null)
            {
                return;
            }

            foreach (var option in newEventDto.NewOptions)
            {
                if (option == null)
                {
                    continue;
                }

                var newOption = new EventOption
                {
                    Created    = DateTime.UtcNow,
                    CreatedBy  = newEventDto.UserId,
                    Modified   = DateTime.UtcNow,
                    ModifiedBy = newEventDto.UserId,
                    Option     = option.Option,
                    Rule       = option.Rule,
                    Event      = newEvent
                };

                _eventOptionsDbSet.Add(newOption);
            }
        }
Ejemplo n.º 3
0
        public void Should_Return_MaxChoices_Validation_Exception_While_Creating_Event()
        {
            MockUsers();
            MockEventTypes();
            var newEvent = new CreateEventDto
            {
                EndDate           = DateTime.UtcNow.AddHours(3),
                StartDate         = DateTime.UtcNow.AddHours(2),
                Name              = "Name",
                TypeId            = 1,
                ImageName         = "qwer",
                Recurrence        = EventRecurrenceOptions.EveryDay,
                MaxOptions        = 0,
                MaxParticipants   = 1,
                OrganizationId    = 1,
                ResponsibleUserId = "1",
                Location          = "place",
                NewOptions        = new List <NewEventOptionDto>
                {
                    new NewEventOptionDto
                    {
                        Option = "Type1"
                    },
                    new NewEventOptionDto
                    {
                        Option = "Type2"
                    }
                }
            };
            var ex = Assert.ThrowsAsync <EventException>(async() => await _eventService.CreateEventAsync(newEvent));

            Assert.That(ex.Message, Is.EqualTo(PremiumErrorCodes.EventNeedToHaveMaxChoiceCode));
        }
Ejemplo n.º 4
0
        public async Task <CreateEventDto> CreateEventAsync(CreateEventDto newEventDto)
        {
            newEventDto.MaxOptions = FindOutMaxChoices(newEventDto.NewOptions.Count(), newEventDto.MaxOptions);
            newEventDto.RegistrationDeadlineDate = SetRegistrationDeadline(newEventDto);

            var hasPermissionToPin = await _permissionService.UserHasPermissionAsync(newEventDto, AdministrationPermissions.Event);

            _eventValidationService.CheckIfUserHasPermissionToPin(newEventDto.IsPinned, currentPinStatus: false, hasPermissionToPin);

            _eventValidationService.CheckIfEventStartDateIsExpired(newEventDto.StartDate);
            _eventValidationService.CheckIfRegistrationDeadlineIsExpired(newEventDto.RegistrationDeadlineDate.Value);
            await ValidateEvent(newEventDto);

            _eventValidationService.CheckIfCreatingEventHasInsufficientOptions(newEventDto.MaxOptions, newEventDto.NewOptions.Count());
            _eventValidationService.CheckIfCreatingEventHasNoChoices(newEventDto.MaxOptions, newEventDto.NewOptions.Count());

            var newEvent = await MapNewEvent(newEventDto);

            _eventsDbSet.Add(newEvent);

            MapNewOptions(newEventDto, newEvent);
            await _uow.SaveChangesAsync(newEventDto.UserId);

            newEvent.Description = _markdownConverter.ConvertToHtml(newEvent.Description);

            newEventDto.Id = newEvent.Id.ToString();

            return(newEventDto);
        }
Ejemplo n.º 5
0
        public async Task Should_Return_Created_Event_Without_Options()
        {
            MockUsers();
            MockEventTypes();
            var newEvent = new CreateEventDto
            {
                EndDate   = DateTime.UtcNow.AddHours(2),
                StartDate = DateTime.UtcNow.AddHours(1),
                Name      = "Name",
                TypeId    = 1,
                ImageName = "qwer",
                Offices   = new EventOfficesDto {
                    Value = "[\"1\"]", OfficeNames = new List <string> {
                        "office"
                    }
                },
                Recurrence        = EventRecurrenceOptions.EveryDay,
                MaxOptions        = 0,
                MaxParticipants   = 1,
                OrganizationId    = 1,
                ResponsibleUserId = "1",
                Location          = "place",
                NewOptions        = new List <NewEventOptionDto>()
            };

            await _eventService.CreateEventAsync(newEvent);

            _eventsDbSet.Received(1).Add(Arg.Any <Event>());
            _eventOptionsDbSet.Received(0).Add(Arg.Any <EventOption>());
        }
Ejemplo n.º 6
0
        public async Task <Result <EventDto> > Create(CreateEventDto createEventDto, Guid userId)
        {
            var category = await Context.Categories.FirstOrDefaultAsync(c => c.Id == createEventDto.CategoryId);

            if (category == null)
            {
                return(Result <EventDto> .Failed(new NotFoundObjectResult(new ApiMessage
                {
                    Message = ResponseMessage.CategoryNotFound
                })));
            }

            var host = await Context.Hosts.FirstOrDefaultAsync(c => c.Id == createEventDto.HostId);

            if (host == null)
            {
                return(Result <EventDto> .Failed(new NotFoundObjectResult(new ApiMessage
                {
                    Message = ResponseMessage.HostNotFound
                })));
            }

            var user = await Context.Users.FirstOrDefaultAsync(c => c.Id == userId);

            if (user == null)
            {
                return(Result <EventDto> .Failed(new NotFoundObjectResult(new ApiMessage
                {
                    Message = ResponseMessage.UserNotFound
                })));
            }


            var newEvent = _mapper.Map <Event>(createEventDto);

            var      dateFromHour = createEventDto.EventSchedule.StartHour;
            var      dateToHour   = createEventDto.EventSchedule.EndHour;
            TimeSpan fromHour;
            TimeSpan toHour;

            if (TimeSpan.TryParse(dateFromHour, out fromHour))
            {
                if (TimeSpan.TryParse(dateToHour, out toHour))
                {
                    newEvent.EventSchedule.StartHour = fromHour;
                    newEvent.EventSchedule.EndHour   = toHour;
                }
            }

            newEvent.EventGallery?.ForEach(e =>
            {
                e.User = user;
                e.Id   = Guid.NewGuid();
            });
            await AddAsync(newEvent);

            await Context.SaveChangesAsync();

            return(Result <EventDto> .SuccessFull(_mapper.Map <EventDto>(newEvent)));
        }
Ejemplo n.º 7
0
        public async Task Should_Return_Created_Event_With_Wall()
        {
            MockUsers();
            MockEventTypes();
            var newEvent = new CreateEventDto
            {
                EndDate   = DateTime.UtcNow.AddHours(2),
                StartDate = DateTime.UtcNow.AddHours(1),
                Name      = "Name",
                TypeId    = 1,
                ImageName = "qwer",
                Offices   = new EventOfficesDto {
                    Value = "[\"1\"]", OfficeNames = new List <string> {
                        "office"
                    }
                },
                Recurrence        = EventRecurrenceOptions.EveryDay,
                MaxOptions        = 0,
                MaxParticipants   = 1,
                OrganizationId    = 1,
                ResponsibleUserId = "1",
                Location          = "place",
                NewOptions        = new List <NewEventOptionDto>()
            };

            await _eventService.CreateEventAsync(newEvent);

            await _wallService.Received(1)
            .CreateNewWallAsync(Arg.Is <CreateWallDto>(x =>
                                                       x.Name == newEvent.Name &&
                                                       x.Access == WallAccess.Private &&
                                                       x.Type == WallType.Events &&
                                                       x.ModeratorsIds.Count() == 1 &&
                                                       x.ModeratorsIds.Any(y => y == newEvent.ResponsibleUserId)));
        }
Ejemplo n.º 8
0
        public CreateEventDto CreateEvent(CreateEventDto eventObj)
        {
            var returnObj = new Event()
            {
                AssignerId   = eventObj.AssignerId,
                AssignerName = eventObj.AssignerName,
                Description  = eventObj.Description,
                Start        = eventObj.Start,
                End          = eventObj.End,
            };

            _db.Event.Add(returnObj);
            Save();

            foreach (var userId in eventObj.Users)
            {
                var eventUsersObj = new EventUsers()
                {
                    UserId  = userId,
                    EventId = returnObj.Id,
                };
                _db.EventUsers.Add(eventUsersObj);
            }

            Save();
            return(eventObj);
        }
Ejemplo n.º 9
0
        public async Task <ServiceResponse <EventDto> > Create(CreateEventDto createRequest, string timezone)
        {
            var @event = await _eventService.AddEventAsync(_calendarId, new Event
            {
                Summary     = createRequest.Title,
                Description = createRequest.Description,
                Start       = new EventDateTime
                {
                    DateTime = createRequest.Start,
                    TimeZone = timezone
                },
                End = new EventDateTime
                {
                    DateTime = createRequest.End,
                    TimeZone = timezone
                }
            });

            if (@event == null)
            {
                return(ServiceResponse <EventDto> .Fail);
            }

            return(new ServiceResponse <EventDto>
            {
                Result = EventsToDto(@event),
                Success = true
            });
        }
Ejemplo n.º 10
0
        public void Should_Return_Registration_Deadline_Greater_Than_Start_Date_Exception_While_Creating_Event()
        {
            MockUsers();
            MockEventTypes();
            _systemClockMock.UtcNow.Returns(DateTime.Parse("2016-04-05"));
            var newEvent = new CreateEventDto
            {
                EndDate   = DateTime.Parse("2016-04-10"),
                StartDate = DateTime.Parse("2016-04-06"),
                RegistrationDeadlineDate = DateTime.Parse("2016-04-07"),
                Name              = "Name",
                TypeId            = 1,
                ImageName         = "qwer",
                Recurrence        = EventRecurrenceOptions.EveryDay,
                MaxOptions        = 1,
                MaxParticipants   = 1,
                OrganizationId    = 1,
                ResponsibleUserId = "1",
                Location          = "place",
                NewOptions        = new List <NewEventOptionDto>
                {
                    new NewEventOptionDto
                    {
                        Option = "Type1"
                    },
                    new NewEventOptionDto
                    {
                        Option = "Type2"
                    }
                }
            };
            var ex = Assert.ThrowsAsync <EventException>(async() => await _eventService.CreateEventAsync(newEvent));

            Assert.That(ex.Message, Is.EqualTo(PremiumErrorCodes.EventRegistrationDeadlineGreaterThanStartDateCode));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> CreateEvent([FromBody] CreateEventDto createEventDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var eventToCreate = new Event
            {
                EventName        = createEventDto.EventName,
                EventDescription = createEventDto.EventDescription,
                EventOwnerId     = currentUserId,
            };

            _repo.Add(eventToCreate);

            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }

            throw new Exception("Failed on save.");
        }
Ejemplo n.º 12
0
        public int Create(CreateEventDto dto)
        {
            var events = _mapper.Map <Event>(dto);

            _dbContext.Events.Add(events);
            _dbContext.SaveChanges();
            return(events.Id);
        }
        public async Task <int> CreateEvent(CreateEventDto createEventDto)
        {
            var eventEntity = _mapper.Map <Event>(createEventDto);

            _context.Events.Add(eventEntity);
            _context.Save();

            return(eventEntity.EventId);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> CreateEventAsync([FromBody] CreateEventDto createEventDto)
        {
            var eventId = Guid.NewGuid();
            await _eventOrganizerService.CreateEventAsync(eventId, UserId, createEventDto);

            var locationUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}/Event/{eventId}";

            return(Created(locationUrl, null));
        }
Ejemplo n.º 15
0
        public IActionResult CreateEvent([FromBody] CreateEventDto createEventDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(_eventService.CreateEvent(createEventDto)));
        }
Ejemplo n.º 16
0
        public async Task CreateAsync(CreateEventDto dto)
        {
            if (_settlementRepository.FindByIdAsync(dto.SettlementId) == null)
            {
                throw new ResourceNotFoundException();
            }

            var @event = Map <CreateEventDto, Event>(dto);
            await _eventRepository.CreateAsync(@event);
        }
Ejemplo n.º 17
0
        public IActionResult CreateEvent([FromBody] CreateEventDto eventObj)
        {
            if (eventObj == null)
            {
                return(BadRequest(ModelState));
            }
            var objList = _evRepo.CreateEvent(eventObj);

            return(Ok(objList));
        }
        public async Task <Dto> CreateEvent <Dto>(CreateEventDto createEventDto)
        {
            Event eventEntity = _mapper.Map <Event>(createEventDto);

            eventEntity.Place = Convert.ToUInt64(new Random().Next(1, 4));
            eventEntity       = await _repository.Add(eventEntity);

            Dto mappedEvent = _mapper.Map <Dto>(eventEntity);

            return(mappedEvent);
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> UpdateEvent(int eventId, [FromBody] CreateEventDto request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            await _eventService.UpdateAsync(eventId, request);

            return(ApiResponseOk(null));
        }
Ejemplo n.º 20
0
        public EventDetailDto Post([FromBody] CreateEventDto eventDto)
        {
            var newEvent = _mapper.Map <ScheduledEvent>(eventDto);

            Request.Headers.TryGetValue("User-Id", out var userId);
            newEvent.CreatedByUserId = Guid.Parse(userId);

            var result = _eventsRepo.Add(newEvent);

            return(_mapper.Map <EventDetailDto>(result));
        }
Ejemplo n.º 21
0
 private void FillContext(CreateEventDto dto)
 {
     dto.Date            = DateTime.UtcNow;
     dto.MachineName     = Environment.MachineName;
     dto.Username        = Environment.UserName;
     dto.OperatingSystem = EnvironmentHelper.GetOperatinSystemName();
     dto.Runtime         = EnvironmentHelper.GetRuntimeVersion();
     dto.OSArchitecture  = EnvironmentHelper.GetOSArchitecture();
     dto.Release         = Assembly.GetEntryAssembly().GetName().Version.ToString();
     dto.Sdk             = ClientDefaults.SdkName;
     dto.SdkVersion      = Assembly.GetExecutingAssembly().GetName().Version.ToString();
 }
Ejemplo n.º 22
0
        public async Task ReportAsync(string message, EventLevel level)
        {
            var dto = new CreateEventDto
            {
                Message = message,
                Level   = level,
            };

            FillContext(dto);

            await ReportEventAsync(dto);
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Post([FromBody] CreateEventDto createEventDto)
        {
            var user = await _userService.GetById(int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)));

            if (createEventDto.PlannerId != user.PlannerId)
            {
                return(BadRequest());
            }

            await _eventService.Create(createEventDto);

            return(Ok());
        }
Ejemplo n.º 24
0
        public async Task UpdateAsync(int eventId, CreateEventDto dto)
        {
            var @event = await _eventRepository.FindByIdAsync(eventId);

            if (@event == null)
            {
                throw new ResourceNotFoundException();
            }

            MapToInstance(dto, @event);

            await _eventRepository.UpdateAsync(@event);
        }
Ejemplo n.º 25
0
        private async Task ValidateEvent(CreateEventDto eventDto)
        {
            var userExists = await _usersDbSet.AnyAsync(u => u.Id == eventDto.ResponsibleUserId);

            var eventTypeExists = await _eventTypesDbSet.AnyAsync(e => e.Id == eventDto.TypeId);

            _eventValidationService.CheckIfEndDateIsGreaterThanStartDate(eventDto.StartDate, eventDto.EndDate);
            // ReSharper disable once PossibleInvalidOperationException
            _eventValidationService.CheckIfRegistrationDeadlineExceedsStartDate(eventDto.RegistrationDeadlineDate.Value, eventDto.StartDate);
            _eventValidationService.CheckIfResponsibleUserNotExists(userExists);
            _eventValidationService.CheckIfOptionsAreDifferent(eventDto.NewOptions);
            _eventValidationService.CheckIfTypeDoesNotExist(eventTypeExists);
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> CreateEvent(CreateEventDto input)
        {
            try
            {
                var eventModel = await _eventAppService.CreateEvent(input);

                return(Ok(eventModel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 27
0
        public async Task <OperationResultWithData <MeetingSessionDTO> > CreateEvent([FromBody] CreateEventDto model)
        {
            try
            {
                LtiParamDTO param = Session.LtiSession.LtiParam;
                var         meetingSessionService = _lmsFactory.GetMeetingSessionService(LmsCompany, param);
                var         eve = await meetingSessionService.CreateSessionAsync(model.MeetingId, param);

                return(eve.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("CreateSession", ex);
                return(OperationResultWithData <MeetingSessionDTO> .Error(errorMessage));
            }
        }
Ejemplo n.º 28
0
        public EventDto CreateEvent(CreateEventDto addEventDto)
        {
            if (!_context.SimpleUsers.Any(x => x.Id == addEventDto.OwnerId))
            {
                return(null);
            }

            var @event = _iMapper.Map <Event>(addEventDto);

            _context.Events.Add(@event);
            _context.SaveChanges();

            var eventDto = _iMapper.Map <EventDto>(@event);

            return(eventDto);
        }
Ejemplo n.º 29
0
        private async Task Consumer_Received(object sender, BasicDeliverEventArgs ea)
        {
            var body               = ea.Body;
            var message            = Encoding.UTF8.GetString(body);
            var outputQueueMessage = new OutputQueueMessage();

            try
            {
                CreateEventDto dto = JsonConvert.DeserializeObject <CreateEventDto>(message);
                outputQueueMessage.Md5 = dto.Md5;
                using (var scope = _serviceProvider.CreateScope())
                {
                    var eventService = scope.ServiceProvider.GetRequiredService <IEventService>();
                    await eventService.CreateAsync(dto);
                }
                outputQueueMessage.EventStatus = EventStatusConstants.SUCCESSFULLY_RECEIVED;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                outputQueueMessage.EventStatus = EventStatusConstants.UNSUCCESSFULLY_RECEIVED;
            }

            try
            {
                var sended = true;
                using (var scope = _serviceProvider.CreateScope())
                {
                    var queueSenderService = scope.ServiceProvider.GetRequiredService <IQueueSenderService>();
                    sended = queueSenderService.SendToQueueOutput(outputQueueMessage);
                }

                if (outputQueueMessage.EventStatus == EventStatusConstants.SUCCESSFULLY_RECEIVED)
                {
                    using (var scope = _serviceProvider.CreateScope())
                    {
                        var eventService = scope.ServiceProvider.GetRequiredService <IEventService>();
                        await eventService.UpdateSendedToOutputAsync(outputQueueMessage.Md5, sended);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 30
0
        public virtual IActionResult AddEvent([FromBody] CreateEventDto createEventDto)
        {
            //TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(201, default(Event));
            //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(0, default(Error));
            string exampleJson = null;

            exampleJson = "null";

            var example = exampleJson != null
            ? JsonConvert.DeserializeObject <Event>(exampleJson)
            : default(Event);

            //TODO: Change the data returned
            return(new ObjectResult(example));
        }