Esempio n. 1
0
        public async Task <JsonResult> GetMessages(string username1, string username2)
        {
            var currentUserName = _userManager.GetUserName(User);

            if (!(currentUserName == username1 || currentUserName == username2 ||
                  User.IsInRole("moderator") || User.IsInRole("administrator")))
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                return(Json(new { message = "Authorization error." }));
            }

            var chat = await _messageManager.GetChatHistory(username1, username2).OrderBy(m => m.SendDate).ToArrayAsync();

            var jsonChat = _messageMapper.MapRange(chat);

            return(Json(jsonChat, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }