示例#1
0
        public async Task <CreateSessionEventResponse> CreateSessionEvent(CreateSessionEventRequest request)
        {
            var sessionUser = await _sessionManager.GetUser();

            var response = new CreateSessionEventResponse();

            var sessionEvents = await _cache.SessionEvents();

            var sessionEvent = sessionEvents.FirstOrDefault(se => se.Key == request.Key);

            if (sessionEvent != null)
            {
                response.Notifications.AddError($"A session event already exists with the key {request.Key}");
                return(response);
            }

            int id;

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                id = await uow.SessionRepo.CreateSessionEvent(new Repositories.DatabaseRepos.SessionRepo.Models.CreateSessionEventRequest()
                {
                    Key         = request.Key,
                    Description = request.Description,
                    Created_By  = sessionUser.Id
                });

                uow.Commit();
            }

            _cache.Remove(CacheConstants.SessionEvents);

            await _sessionManager.WriteSessionLogEvent(new Models.ManagerModels.Session.CreateSessionLogEventRequest()
            {
                EventKey = SessionEventKeys.SessionEventCreated,
                Info     = new Dictionary <string, string>()
                {
                    { "Key", request.Key }
                }
            });

            response.Notifications.Add($"Session event '{request.Key}' has been created", NotificationTypeEnum.Success);
            return(response);
        }
示例#2
0
        public async Task <CreateSessionEventResponse> CreateSessionEvent(CreateSessionEventRequest request)
        {
            var session = await _sessionService.GetAuthenticatedSession();

            var response = new CreateSessionEventResponse();

            var sessionEvents = await _cache.SessionEvents();

            var sessionEvent = sessionEvents.FirstOrDefault(se => se.Key == request.Key);

            if (sessionEvent != null)
            {
                response.Notifications.AddError($"A session event already exists with the key {request.Key}");
                return(response);
            }

            int id;

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                id = await uow.SessionRepo.CreateSessionEvent(new Infrastructure.Repositories.SessionRepo.Models.CreateSessionEventRequest()
                {
                    Key         = request.Key,
                    Description = request.Description,
                    Created_By  = session.User.Entity.Id
                });

                uow.Commit();
            }

            _cache.Remove(CacheConstants.SessionEvents);

            await _sessionService.WriteSessionLogEvent(new Models.ServiceModels.Session.CreateSessionLogEventRequest()
            {
                EventKey = SessionEventKeys.SessionEventCreated
            });

            response.Notifications.Add($"Session event '{request.Key}' has been created", NotificationTypeEnum.Success);
            return(response);
        }