コード例 #1
0
        public async Task <IHttpActionResult> Get()
        {
            var deviceSerial = _SessionInfo.DeviceSerial;

            if (string.IsNullOrEmpty(deviceSerial))
            {
                DataClassesManager.ControllerLog("error", _User.Id, this.Request.RequestUri.PathAndQuery, string.Format("{0}:{1}", _User.Username, "SerialHeaderRequired"));
                return(BadRequest("SerialHeaderRequired"));
            }
            //var activeSession = context.UserSession.Where(x => x.UserId == user.UserId).OrderByDescending(x => x.LoggedAt).Take(1).SingleOrDefault();
            //if (activeSession.DeviceSerial != deviceSerial)
            //{
            //    var ac = activeSession.DeviceSerial;
            //    DataClassesManager.ControllerLog("error", id, this.Request.RequestUri.PathAndQuery, string.Format("{0}:{1}-current:{2}-active:{3}", user.Username, "Conflict", activeSession.DeviceSerial, deviceSerial));
            //    return Conflict();
            //}
            var errorMessage = "";
            var result       = DataClassesManager.GetPendingChat(_User.UserId.Value, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                DataClassesManager.ControllerLog("error", _User.Id, this.Request.RequestUri.PathAndQuery, string.Format("{0}:{1}", _User.Username, errorMessage));
                return(BadRequest(errorMessage));
            }
            var chatGroupedBySender = result.GroupBy(x => new { x.Group, x.Sender }, x => new { Id = x.Id, Type = x.Type, Content = x.Content, IssuedAt = x.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT), ExpiresAt = x.ExpiresAt, SizeInBytes = x.SizeInBytes, Duration = x.Duration, IsScrambled = x.IsScrambled })
                                      .Select(grp => new {
                sender = grp.Key.Sender,
                group  = grp.Key.Group,
                chat   = grp.ToList().OrderBy(x => x.IssuedAt)
            }).ToList();

            DataClassesManager.ControllerLog("info", _User.Id, this.Request.RequestUri.PathAndQuery, string.Format("{0}:count={1}", _User.Username, result.Count));

            return(Ok(chatGroupedBySender));
        }