Beispiel #1
0
        public async Task <bool> UpdateEntityByIdAsync(ChatUpdateRequest request, int id)
        {
            var entity = _mapper.Map <ChatUpdateRequest, Chat>(request);

            entity.Id = id;

            foreach (var settings in entity.UsersSettings)
            {
                if (settings.Id == 0)
                {
                    await _uow.NotificationSettingsRepository.CreateAsync(settings);
                }
                else
                {
                    await _uow.NotificationSettingsRepository.UpdateAsync(settings);
                }
            }

            // In returns updated entity, you could do smth with it or just leave as it is
            var updated = await _uow.ChatsRepository.UpdateAsync(entity);

            var result = await _uow.SaveAsync();

            return(result);
        }
Beispiel #2
0
 public void Update(ChatUpdateRequest model)
 {
     DataProvider.ExecuteNonQuery("dbo.Chat_Update",
                                  inputParamMapper : delegate(SqlParameterCollection paramCollection)
     {
         paramCollection.AddWithValue("@ChatName", model.ChatName);
         paramCollection.AddWithValue("@Id", model.Id);
     });
 }
Beispiel #3
0
 public void Update(ChatUpdateRequest model)
 {
     DataProvider.ExecuteNonQuery("dbo.Chat_Update",
                                  inputParamMapper: (SqlParameterCollection inputs) =>
     {
         inputs.AddWithValue("@Id", model.Id);
         inputs.AddWithValue("@ChatTitle", model.ChatTitle);
     });
 }
        public ActionResult <GetChatResponce> GetRecentUpdates(
            ChatUpdateRequest updateRequest)
        {
            var res = service.GetChatUpdates(updateRequest);

            if (res == null)
            {
                return(NotFound());
            }
            return(Ok(res));
        }
Beispiel #5
0
 public HttpResponseMessage Put(ChatUpdateRequest model)
 {
     try
     {
         _chatService.Update(model);
         return(Request.CreateResponse(HttpStatusCode.OK, new SuccessResponse()));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
        public virtual async Task <ActionResult> Update([FromRoute] int id, [FromBody] ChatUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _chatsService.UpdateEntityByIdAsync(request, id);

            if (!result)
            {
                return(StatusCode(500));
            }

            return(NoContent());
        }
    public IHttpActionResult Put(ChatUpdateRequest model)
    {
        try
        {
            _chatService.Update(model);
            return(Ok(new SuccessResponse()));
        }
        catch (Exception ex)
        {
            int currentUser = _userService.GetCurrentUserId();
            _appLogService.Insert(new AppLogAddRequest
            {
                AppLogTypeId = 1,
                Message      = ex.Message,
                StackTrace   = ex.StackTrace,
                Title        = "Error in " + GetType().Name + " " + System.Reflection.MethodBase.GetCurrentMethod().Name,
                UserBaseId   = currentUser
            });

            return(BadRequest(ex.Message));
        }
    }
Beispiel #8
0
        public async Task UpdateChat(ChatUpdateRequest chat, int chatId)
        {
            var result = await _chatsService.UpdateEntityByIdAsync(chat, chatId);

            if (!result)
            {
                return;
            }

            var changedChat = await _chatsService.GetEntityByIdAsync(chatId);

            foreach (var user in changedChat.Users)
            {
                if (!UsersConnections.ContainsKey(user.Id))
                {
                    continue;
                }
                foreach (string connectionId in UsersConnections[user.Id])
                {
                    await Clients.Client(connectionId).SendAsync("ChatChanged", changedChat);
                }
            }
        }
        public GetChatResponce GetChatUpdates(ChatUpdateRequest req)
        {
            var d = GetDateTimeFromUnixTimeStamp(req.LastMessageSentAt);

            return(collection
                   .Find(c => c.Id == req.ChatId && c.UpdatedAt >= req.LastMessageSentAt)
                   .Project(c => new GetChatResponce {
                Members = c.Members,
                UpdatedAt = c.UpdatedAt,
                Messages = c.MessageLists
                           .Where(ml =>
                                  ml.Year > d.Year ||
                                  (ml.Year == d.Year && ml.Month > d.Month) ||
                                  (ml.Year == d.Year && ml.Month == d.Month && ml.Day >= d.Day))
                           .SelectMany(ml =>
                                       ml.Messages.Where(m =>
                                                         (m.SentAt > req.LastMessageSentAt) ||
                                                         (m.SentAt == req.LastMessageSentAt &&
                                                          m.AuthorUserId != req.LastAuthorUserId)))
                           .ToList(),
                CreatedAt = c.CreatedAt,
                Id = c.Id
            }).FirstOrDefault());
        }