Пример #1
0
        private void writeToSellerClicked(object sender, RoutedEventArgs e)
        {
            FarmersMarketContext context        = new FarmersMarketContext((Application.Current as App).ConnectionString);
            ChatService          chatService    = new ChatService(context);
            ProfileService       profileService = new ProfileService(context);

            Chat chat;

            if ((Application.Current as App).currentUser == null)
            {
                MessageBox.Show("Вы не авторизованы в системе");
                return;
            }
            if (chatService.Get(SellerId, profileService.GetCustomer((Application.Current as App).currentUser).Id) == null)             // Если чата нет
            {
                chat = new Chat
                {
                    SellerId   = SellerId,
                    CustomerId = profileService.GetCustomer((Application.Current as App).currentUser).Id
                };
                chatService.Create(chat.SellerId, chat.CustomerId);
            }
            else             // если чат есть
            {
                chat = chatService.Get(SellerId, profileService.GetCustomer((Application.Current as App).currentUser).Id);
            }

            ChatWindow chatWindow = new ChatWindow(chat);

            chatWindow.ShowDialog();
        }
Пример #2
0
 private void AddMessage(string username, string message)
 {
     _chatService.Create(new ChatMessage()
     {
         Sender  = username,
         Message = message
     });
 }
Пример #3
0
 public ActionResult <Chat> Post([FromBody] Chat chat)
 {
     try {
         _chatService.Create(chat);
         return(Ok(chat));
     } catch (Exception e) {
         return(BadRequest("Erro ao salvar chat"));
     }
 }
Пример #4
0
        public ActionResult Accept(string idFrindRequest, string returnUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(idFrindRequest))
                {
                    return(NotFound());
                }

                var user = userService.Get(HttpContext.Session.GetString("UserId"));
                if (user.FriendRequests.Any(u => u.Id == idFrindRequest))
                {
                    FriendRequest request = user.FriendRequests.Single(u => u.Id == idFrindRequest);
                    var           friend  = userService.Get(request.UserId);
                    user.FriendRequests.Remove(request);
                    user.Friends.Add(request.UserId);
                    friend.Friends.Add(user.Id);
                    userService.Update(friend.Id, friend);
                    userService.Update(user.Id, user);
                    Chat chat = new Chat()
                    {
                        Friends = new List <string>()
                        {
                            user.Id,
                            friend.Id
                        },
                        Content = new List <ChatContent>()
                    };
                    chatService.Create(chat);
                }
                else
                {
                    return(View("Error", new ErrorViewModel()));
                }
                if (Url.IsLocalUrl(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(View("Error", new ErrorViewModel()));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(View("Error", new ErrorViewModel()));
            }
        }
Пример #5
0
 public ActionResult <ChatDetails> Create(ChatDetails events)
 {
     _eventService.Create(events);
     return(CreatedAtRoute("GetEvents", new { id = events.Id.ToString() }, events));
 }
Пример #6
0
        public ActionResult <ChatMessage> Create(ChatMessage message)
        {
            _chatService.Create(message);

            return(CreatedAtRoute("GetMessage", new { id = message.Id.ToString() }, message));
        }
Пример #7
0
        public ActionResult <Chat> Create(Chat chat)
        {
            _chatService.Create(chat);

            return(CreatedAtRoute("GetByCourse", new { id = chat._id.ToString() }, chat));
        }
Пример #8
0
 public void Create([FromBody] ChatCreateRequest chatCreateRequest)
 {
     _chatService.Create(chatCreateRequest);
 }