Exemplo n.º 1
0
        public async void setStatus(string Name)
        {
            data = await _service.login.SingleOrDefaultAsync(e => e.Name == Name);

            data.isConnected = "1";
            _service.login.Attach(data);
            _service.Entry(data).State = EntityState.Modified;
            _service.SaveChanges();
        }
Exemplo n.º 2
0
        public bool SendMessage(string message, string emailReceiver, User sender, int conversationId)
        {
            try
            {
                var conversation = _context.Conversations.FirstOrDefault(c => c.Id == conversationId);
                if (conversation == null)
                {
                    return(false);
                }
                var returnMessage     = new Message();
                var aesKey            = EncryptionServices.GetAesKey();
                var aesIv             = EncryptionServices.GetAesIV();
                var publicKeyReceiver = _context.PublicKeyStores.FirstOrDefault(s => s.Email == emailReceiver)?.PublicKey;

                var encryptedMessageWithAes = EncryptionServices.EncryptWithAes(aesKey, aesIv, message);
                var encryptedAesKeyWithRsa  = EncryptionServices.EncryptWithRsa(aesKey, publicKeyReceiver);
                var encryptedAesIVWithRsa   = aesIv;

                returnMessage = new Message {
                    EmailOfSender             = sender.Email,
                    ConversationId            = conversationId,
                    EncryptedAesIV            = encryptedAesIVWithRsa,
                    EncryptedAesKey           = encryptedAesKeyWithRsa,
                    EncryptedContentOfMessage = encryptedMessageWithAes,
                    SignedData = EncryptionServices.SingData(message, sender.PrivateKey),
                };

                conversation.Messages.Add(returnMessage);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(false);
            }
        }
Exemplo n.º 3
0
        private void AddKeysToDb(RegisterModel model)
        {
            var user = _context.Users.FirstOrDefault(u => u.Email == model.Email);
            var encryptionServices = new EncryptionServices();
            var aesIv = EncryptionServices.GetAesIV();

            user.AesIv      = aesIv;
            user.PrivateKey = encryptionServices.GetPrivateKey();
            _context.PublicKeyStores.Add(new PublicKeyStore
            {
                Email     = model.Email,
                PublicKey = encryptionServices.GetPublicKey()
            });
            _context.SaveChanges();
        }
Exemplo n.º 4
0
        public ResponseData SignUp(UserSignUp registration)
        {
            try
            {
                //It checks emailaddress should not exist
                var checkData = database.UserDetails.Where(exist => exist.EmailAddress == registration.EmailAddress).
                                FirstOrDefault();
                if (checkData == null)
                {
                    //Request Body
                    UserRegistration user = new UserRegistration()
                    {
                        FirstName      = registration.FirstName,
                        LastName       = registration.LastName,
                        EmailAddress   = registration.EmailAddress,
                        Password       = registration.Password,
                        RegisteredDate = DateTime.Now
                    };
                    database.Add(user);
                    database.SaveChanges();

                    //Response Body
                    ResponseData responseData = new ResponseData()
                    {
                        UserId         = user.UserId,
                        FirstName      = user.FirstName,
                        LastName       = user.LastName,
                        EmailAddress   = user.EmailAddress,
                        RegisteredDate = user.RegisteredDate
                    };
                    return(responseData);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 5
0
 public void Commit()
 {
     dbContext.SaveChanges();
 }
 /// <summary>
 /// Подтвердить изменения.
 /// </summary>
 public void Commit()
 {
     // Сохраняем все изменения в контекстк базы данных
     dbContext.SaveChanges();
 }
Exemplo n.º 7
0
 public void Add(Conversation newConversation)
 {
     _context.Conversations.Add(newConversation);
     _context.SaveChanges();
 }