Esempio n. 1
0
        public bool SendContact(string sessionKey, Shared.Dto.Contact contact)
        {
            var dbContext = DbContextFactory.GetContext();

            var sessionService = new SessionService();
            var user = sessionService.GetUser(sessionKey);
            if (user == null) return false;

            User recipient;
            try
            {
                recipient =
                    dbContext.Users.Single(u => u.Id == contact.ReceiverId);
            }
            catch (Exception)
            {
                return false;
            }

            var newContact = new Contact
            {
                PublicKey = contact.PublicKey,
                Name = contact.Name,
                Sender = user,
                Recipient = recipient
            };

            dbContext.Add(newContact);
            dbContext.SaveChanges();

            var userService = new PushService();
            userService.Push(recipient, "Recieved new contact!");

            return true;
        }
Esempio n. 2
0
        public bool SendMessage(string sessionKey, Shared.Dto.Message msg)
        {
            var dbContext = DbContextFactory.GetContext();

            var sessionService = new SessionService();
            var user = sessionService.GetUser(sessionKey);
            if (user == null)
            {
                return false;
            }

            User recipient;
            try
            {
                recipient =
                    dbContext.Users.Single(u => u.Id == msg.ReceiverId);
            }
            catch (Exception)
            {
                return false;
            }

            var newMsg = new Message
            {
                Content = msg.Body,
                Sender = user,
                Recipient = recipient,
                SentTime = msg.DateSent,
                Signature = msg.DigitalSignature,
                SessionKey = msg.SymmetricKey,
                InitVector = msg.Iv

            };

            var userService = new PushService();
            userService.Push(recipient, "You have new message");

            dbContext.Add(newMsg);
            dbContext.SaveChanges();

            return true;
        }