Beispiel #1
0
        public Task <ActionResult <EventViewModel> > PutAsync(Guid id, [FromBody] EventUpdateInputModel inputModel)
        => ExecuteAsync <EventViewModel>(async() =>
        {
            if (inputModel == null)
            {
                return(BadRequest());
            }

            var @event = await _eventsRepository.GetByIdAsync(
                id,
                includes: e => e
                .Include(r => r.Attendees)
                .ThenInclude(a => a.User)
                );

            if (@event == null)
            {
                return(NotFound());
            }

            if (inputModel.Date.HasValue)
            {
                @event.SetDate(inputModel.Date.Value);

                BackgroundJob.Delete(@event.NotificationEventId);
                var jobId = BackgroundJob.Schedule <NotificationService>(s => s.HandleEventNotification(@event.Id), @event.Date - TimeSpan.FromDays(1));
                @event.SetNotificationEventId(jobId);
            }

            if (inputModel.Duration.HasValue)
            {
                @event.SetDuration(inputModel.Duration.Value);
            }

            if (!string.IsNullOrWhiteSpace(inputModel.Description))
            {
                @event.SetDescription(inputModel.Description);
            }

            await _eventsRepository.UpdateAsync(@event);
            return(Ok((EventViewModel)@event));
        });
Beispiel #2
0
        public async Task <ActionResult> Update([FromBody] EventUpdateInputModel inputModel)
        {
            var result = await this.eventService.UpdateAsync(inputModel.Id, inputModel.Title, inputModel.Description, inputModel.PictureUrl, inputModel.When, this.User.GetCurrentUserId());

            return(this.Ok(result));
        }