Ejemplo n.º 1
0
        public int CreateEvent(string loginedUserId, Event @event, int timeOffset)
        {
            var(dataUser, dataCalendar) = serviceHelper.IsUserHasAccessToCalendar(loginedUserId, @event.CalendarId);
            if (dataCalendar != null)
            {
                if ([email protected](DateTimeKind.Utc))
                {
                    @event.Start  = @event.Start.AddMinutes(timeOffset);
                    @event.Finish = @event.Finish.AddMinutes(timeOffset);
                }

                Data.Models.Event dataEvent = Mapper.Map <Event, Data.Models.Event>(@event);
                dataEvent.CreatorId = dataUser.IdUser;
                int eventId = serviceHelper.WrapMethodWithReturn(() => eventRepos.CreateEvent(dataEvent), -1);
                if (eventId > 0)
                {
                    if (@event.Notify != null && @event.Notify.Value > 0)
                    {
                        notificationRepos.CreateNotification(eventId, @event.Notify.Value, (int)@event.Notify.TimeUnit);
                    }
                }
                return(eventId);
            }
            return(-1);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateEvent([FromForm] UserEvents userEvents, [FromHeader] string authorization)
        {
            try {
                string apiKey;

                if (authorization == null)
                {
                    _logger.LogDebug("User with apiKey:{$apiKey} received this event response:{message}", authorization, "Access denied...");
                    return(Unauthorized("Access denied..."));
                }
                else
                {
                    apiKey = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
                    _logger.LogInformation("User with apiKey:{$apiKey} sent this event request:{@userEvents}", apiKey, userEvents);
                }

                if (await _repositoryEvent.CreateEvent(userEvents) == "EventId already exists")
                {
                    _logger.LogDebug("User with apiKey:{$apiKey} received this event response:{message}", apiKey, "Event belongs to another user...");
                    return(BadRequest("Event belongs to another user..."));
                }
                else
                {
                    _logger.LogInformation("User with apiKey:{$apiKey} received this event response:{message}", apiKey, "Event have been created...");
                    return(Ok("Event have been created..."));
                }
            }
            catch (Exception exception)
            {
                _logger.LogError("Exception message:{exception}", exception);
                throw;
            }
        }