Esempio n. 1
0
        public IActionResult OpenSession(int id)
        {
            Session newSession = new Session()
            {
                UserId    = id,
                OpenedDt  = DateTime.Now,
                ExpiresDt = DateTime.Now + TimeSpan.FromHours(1)
            };
            string newSessionId = sessionContext.RegisterSession(newSession);

            IActionResult response = null;

            if (!string.IsNullOrEmpty(newSessionId))
            {
                OpenSessionResponse openResp = new OpenSessionResponse()
                {
                    SessionId = newSessionId
                };

                logger.LogInformation($"Session opened OK: {newSessionId}");

                response = Created("api/v1/session/" + newSessionId, JsonConvert.SerializeObject(openResp));
            }
            else
            {
                logger.LogWarning($"Session opened failed (sessionContext.RegisterSession): {newSessionId}");
                response = StatusCode((int)HttpStatusCode.InternalServerError);
            }

            return(response);
        }
Esempio n. 2
0
        public HttpResponseMessage OpenSession(int id)
        {
            Session newSession = new Session()
            {
                UserId    = id,
                OpenedDt  = DateTime.Now,
                ExpiresDt = DateTime.Now + TimeSpan.FromHours(1)
            };
            string newSessionId = sessionContext.RegisterSession(newSession);

            HttpResponseMessage response = new HttpResponseMessage();

            if (!string.IsNullOrEmpty(newSessionId))
            {
                OpenSessionResponse openResp = new OpenSessionResponse()
                {
                    SessionId = newSessionId
                };
                response.StatusCode = HttpStatusCode.Created;
                response.Content    = new StringContent(JsonConvert.SerializeObject(openResp));
            }
            else
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }