Пример #1
0
        public async Task <IActionResult> PickFavMessagePost([FromBody] FavoriteMessageModel favMessage)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claims         = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            if (claims.Value == null)
            {
                return(NotFound());
            }

            var roomNo = _queueService.GetRoomNoByUserId(claims.Value);

            var message = _repo.FavoriteAdditionalMessage.FindByCondition(m => m.Id == favMessage.Id).FirstOrDefault();

            if (message != null)
            {
                try
                {
                    await _queueService.NewAdditionalInfo(claims.Value, message.Message);

                    await _queueHubContext.SendAdditionalInfo(roomNo, claims.Value, message.Message);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message);
                }
                return(Ok(message.Message));
            }
            return(BadRequest());
        }
Пример #2
0
        public async Task <IActionResult> AddFavoriteMessage([FromBody] FavoriteMessageModel favMessage)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            if (favMessage.Message != null && favMessage.Message.Length > 0)
            {
                var favMsg = new Entities.Models.FavoriteAdditionalMessage
                {
                    Message = favMessage.Message,
                    UserId  = claim.Value
                };

                await _repo.FavoriteAdditionalMessage.AddAsync(favMsg);

                await _repo.SaveAsync();

                return(Ok());
            }
            return(BadRequest());
        }
Пример #3
0
        public async Task <IActionResult> DeleteFavMessage([FromBody] FavoriteMessageModel favMessage)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claims         = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            if (claims.Value == null)
            {
                return(StatusCode(500));
            }

            var favMessages = _repo.FavoriteAdditionalMessage.FindByCondition(u => u.UserId == claims.Value && u.Id != favMessage.Id).ToList();
            var message     = _repo.FavoriteAdditionalMessage.FindByCondition(m => m.Id == favMessage.Id).SingleOrDefault();

            if (message != null)
            {
                _repo.FavoriteAdditionalMessage.Delete(message);
                await _repo.SaveAsync();

                return(Ok(favMessages));
            }
            return(BadRequest());
        }