Exemplo n.º 1
0
        public async Task <bool> UpdateMessage(Message message)
        {
            if (_context.Messages.Any(m => m.Id == message.Id))
            {
                _context.Attach <Message>(message);
            }
            else
            {
                _context.Messages.Add(message);
            }

            return(await _context.SaveChangesAsync() >= 0);
        }
Exemplo n.º 2
0
        public async Task <bool> DeleteChatFor(long chatId, long deleteFor)
        {
            bool success = false;

            try
            {
                using (dbContext = new SignalRChatContext())
                {
                    UserChat userChat = await(from x in dbContext.UserChat
                                              where x.Chatid == chatId
                                              select x).FirstOrDefaultAsync();

                    if (userChat != null && (userChat.Deletedfor > 0 || deleteFor < 0))
                    {
                        dbContext.Remove(userChat);
                    }
                    else
                    {
                        userChat.Deletedfor = deleteFor;
                        dbContext.Update(userChat);
                    }

                    await dbContext.SaveChangesAsync();

                    success = true;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(success);
        }
Exemplo n.º 3
0
        public async Task <object> saveUserChat(vmMessage _model)
        {
            string message = string.Empty;

            try
            {
                using (_ctx = new SignalRChatContext())
                {
                    UserChat model = new UserChat()
                    {
                        Chatid        = _ctx.UserChat.DefaultIfEmpty().Max(x => x == null ? 0 : x.Chatid) + 1,
                        Connectionid  = _model.Connectionid,
                        Senderid      = _model.Senderid,
                        Receiverid    = _model.Receiverid,
                        Message       = _model.Message,
                        Messagestatus = _model.Messagestatus,
                        Messagedate   = _model.Messagedate,
                        IsGroup       = _model.IsGroup,
                        IsPrivate     = _model.IsPrivate,
                        IsMultiple    = _model.IsMultiple
                    };
                    _ctx.UserChat.Add(model);
                    await _ctx.SaveChangesAsync();

                    message = "Saved";
                }
            }
            catch (Exception ex)
            {
                message = "Error:" + ex.ToString();
            }
            return(message);
        }
Exemplo n.º 4
0
        public async Task <UserChat> SaveItemAsync(UserChat item)
        {
            try
            {
                using (dbContext = new SignalRChatContext())
                {
                    EntityEntry <UserChat> newItem = dbContext.UserChat.Add(item);
                    await dbContext.SaveChangesAsync();

                    return(newItem.Entity);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
 public async Task <bool> SaveAsync()
 {
     return(await _ctx.SaveChangesAsync() >= 0);
 }