public async Task <IActionResult> PutConversation(int id, Conversation conversation)
        {
            if (id != conversation.id)
            {
                return(BadRequest());
            }

            _context.Entry(conversation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConversationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutMessage(int id, Message message)
        {
            if (id != message.id)
            {
                return(BadRequest());
            }

            _context.Entry(message).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
 public async Task <UserLogin> AddUserAsync(UserLogin info)
 {
     _context.Add(info);
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (System.Exception exp)
     {
         _Logger.LogError($"Error in {nameof(AddUserAsync)}: " + exp.Message);
     }
     return(info);
 }
Ejemplo n.º 5
0
 public async Task <Messages> AddMsgAsync(Messages data)
 {
     _context.Add(data);
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (System.Exception exp)
     {
         _Logger.LogError($"Error in {nameof(AddMsgAsync)}: " + exp.Message);
     }
     return(data);
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> AddUser([FromBody] User user)
        {
            if (user.Name == null || user.Password == null)
            {
                return(BadRequest("Username and Password must be not null."));
            }
            else
            {
                User _user = await dbContext.Users.FirstOrDefaultAsync(u => u.Name == user.Name);

                if (_user == null)
                {
                    var __user = new User {
                        Name = user.Name, Password = user.Password
                    };
                    dbContext.Users.Add(__user);
                    await dbContext.SaveChangesAsync();

                    return(new JsonResult(__user));
                }
                else
                {
                    return(BadRequest("Username already exist."));
                }
            }
        }
Ejemplo n.º 7
0
        public async Task SendMessage(Message message)
        {
            dbContext.Messages.Add(message);
            await dbContext.SaveChangesAsync();

            if (Context.User.Identity.Name != message.UserTo)
            {
                await Clients.User(Context.User.Identity.Name).SendAsync("SendMessage", message);
            }
            await Clients.User(message.UserTo).SendAsync("SendMessage", message);
        }
Ejemplo n.º 8
0
        private void AddMessageinCache(string userName, string message)
        {
            CurrentMessage.Add(new MessageDetail {
                UserName = userName, Message = message
            });
            dbcontext.Messages.Add(new Message {
                UserName = userName, Text = message, sendTime = DateTime.Now
            });
            dbcontext.SaveChangesAsync();

            if (CurrentMessage.Count > 100)
            {
                CurrentMessage.RemoveAt(0);
            }
        }