Ejemplo n.º 1
0
        public ActionResult CreateChat(int?package)
        {
            User whichuser = (User)UserAuthentication.Identity();
            long studioID  = (long)ViewBag.StudioID;

            var checkchatkey = ent.ChatKeys.FirstOrDefault(x => x.ChatKey_Key == "studiokey" + studioID + "userkey" + whichuser.id);

            if (checkchatkey == null)
            {
                checkchatkey             = new ChatKey();
                checkchatkey.ChatKey_Key = "studiokey" + studioID + "userkey" + whichuser.id;
                checkchatkey.UserID      = whichuser.id;

                checkchatkey.StudioID = (int)studioID;
                ent.ChatKeys.Add(checkchatkey);

                ent.SaveChanges();
            }

            if (package.HasValue)
            {
                TempData["Package"] = package;
            }
            return(Redirect(string.Format("/{0}?key={1}", "Chat", checkchatkey.ChatKeyID)));
        }
Ejemplo n.º 2
0
        //Every time the database changes, this function has to update the List of Messages(MessagesList) to load the other messages
        public async Task Streaming()
        {
            EventStreamResponse response;

            string InverseChatKey = String.Empty;

            string[] usersKey = ChatKey.Split('_');

            InverseChatKey = usersKey[1] + "_" + usersKey[0];

            //This will be called when the RTD changes (and the user started the chat)
            response = await FiresharpClient.OnAsync(ChatKey, (sender, args, context) =>
            {
                getMessage(); //Refresh() == Read the rtDB and update MessagesList
            });

            //This will be called when the RTD changes (and the user didn't start the chat)
            response = await FiresharpClient.OnAsync(InverseChatKey, (sender, args, context) =>
            {
                getMessage(); //Refresh() == Read the rtDB and update MessagesList
            });

            //This disable the streaming function
            //response.Dispose();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> AcceptOrDecline(Invitation newInvitation)
        {
            try
            {
                if (newInvitation.Status == "accepted")
                {
                    var Sender   = _userService.GetUserByUsername(newInvitation.Sender);
                    var Receiver = _userService.GetUserByUsername(newInvitation.Receiver);

                    //GENERAMOS LA LLAVE PÚBLICA PARA CADA USUARIO
                    var senderPublicKey   = ChatSingleton.Instance.DiffiHell.GeneratePublicKey(Sender.Code);
                    var receiverPublicKey = ChatSingleton.Instance.DiffiHell.GeneratePublicKey(Receiver.Code);

                    Sender.Password   = null;
                    Sender.Code       = 0;
                    Receiver.Password = null;
                    Receiver.Code     = 0;

                    ChatKey chatKey = new ChatKey
                    {
                        Id          = null,
                        Sender      = newInvitation.Sender,
                        Receiver    = newInvitation.Receiver,
                        KeySender   = senderPublicKey,
                        KeyReceiver = receiverPublicKey
                    };

                    Contact userContact = new Contact
                    {
                        Id     = null,
                        Owner  = newInvitation.Receiver,
                        Friend = Sender
                    };

                    Contact senderContact = new Contact
                    {
                        Id     = null,
                        Owner  = newInvitation.Sender,
                        Friend = Receiver
                    };

                    await _contactService.CreateContact(userContact);

                    await _contactService.CreateContact(senderContact);

                    await _chatKeyService.CreateChatKeys(chatKey);
                }
                _invitationService.UpdateInvitation(newInvitation.Id, newInvitation);
                return(Ok());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(BadRequest());
            }
        }
Ejemplo n.º 4
0
        private async Task <ActionResult> LoadChatAsync(int?key)
        {
            //ChatMain Page
            if (key.HasValue)
            {
                ChatKey chat = ent.ChatKeys.FirstOrDefault(x => x.ChatKeyID == key);
                if (chat != null)
                {
                    FirestoreDb firestore = FirestoreDb.Create("photogw2");

                    string docID;
                    var    collection = firestore.Collection("Quotation");
                    var    snapshot   = await collection.WhereEqualTo("ChatKey", chat.ChatKeyID).GetSnapshotAsync();

                    if (snapshot.Count() != 0)
                    {
                        docID = snapshot.Documents.FirstOrDefault().Id;
                    }

                    else
                    {
                        var arr = new Dictionary <string, object>().ToArray();
                        Dictionary <string, object> data = new Dictionary <string, object>
                        {
                            { "ChatKey", chat.ChatKeyID }
                        };
                        var submitData = collection.Document();
                        await submitData.SetAsync(data);

                        docID = submitData.Id;
                    }

                    if (ViewBag.StudioID != null)
                    {
                        int studioID = (int)ViewBag.StudioID;
                        ViewBag.PackageList = ent.Packages.Where(x => x.studioid == studioID && x.status.ToLower() != "disabled").ToList();
                    }
                    ViewBag.QuotationID = docID;
                    if (TempData["Package"] != null)
                    {
                        ViewBag.SelectedPackageID = TempData["Package"];
                    }
                    return(View("ChatMain", chat));
                }
            }

            //Chat List Page
            List <ChatKey> chatlist;

            if (ViewBag.StudioID != null)
            {
                long studioID = (long)ViewBag.StudioID;
                chatlist = ent.ChatKeys.Where(x => x.StudioID == studioID).ToList();
            }
            else
            {
                User whichuser = (User)UserAuthentication.Identity();
                chatlist = ent.ChatKeys.Where(x => x.UserID == whichuser.id).ToList();
            }

            return(View("ChatList", chatlist));
        }
Ejemplo n.º 5
0
        public async Task <ChatKey> CreateChatKeys(ChatKey newChatKeys)
        {
            await _chatKeys.InsertOneAsync(newChatKeys);

            return(newChatKeys);
        }