Exemple #1
0
        public async Task Handle(RequestToConfirmUserAccountLoandEvent @event)
        {
            using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.ProgramName}"))
            {
                _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.ProgramName, @event);

                // find the user in the database
                var user = this._userContext.Users.Where(X => X.Id.Equals(@event.UserId)).FirstOrDefault();

                if (user != default || user != null)
                {
                    // check the salary and expensive
                    if (user.MonthlySalary - user.MonthlyExpenses < 1000)
                    {
                        var rejectIntegrationEvent = new RejectAccountLoanForUserEvent(@event.UserId, @event.Loan);
                        rejectIntegrationEvent.EventIdSynchronizationId = @event.EventIdSynchronizationId;
                        await this._userIntegrationEventService.SaveEventAndUserContextChangesAsync(rejectIntegrationEvent);

                        await this._userIntegrationEventService.PublishThroughEventBusAsync(rejectIntegrationEvent);
                    }
                    else
                    {
                        var confirmedIntegratonEvent = new ConfirmUserAccountForLoanIntegrationEvent(@event.UserId, @event.Loan, @event.AccountType);
                        confirmedIntegratonEvent.EventIdSynchronizationId = @event.EventIdSynchronizationId;
                        await this._userIntegrationEventService.SaveEventAndUserContextChangesAsync(confirmedIntegratonEvent);

                        await this._userIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegratonEvent);
                    }
                }
                else
                {
                    var usernotfoundEvent = new UserNotFoundEvent(@event.UserId, @event.Loan);
                    usernotfoundEvent.EventIdSynchronizationId = @event.EventIdSynchronizationId;

                    await this._userIntegrationEventService.SaveEventAndUserContextChangesAsync(usernotfoundEvent);

                    await this._userIntegrationEventService.PublishThroughEventBusAsync(usernotfoundEvent);
                }
            }
        }
Exemple #2
0
        public void OnDataChange(DataSnapshot snapshot)
        {
            if (snapshot.Exists())
            {
                DriverPersonal = new Driver
                {
                    Fname  = (snapshot.Child("fname") != null) ? snapshot.Child("fname").Value.ToString() : "",
                    Lname  = (snapshot.Child("lname") != null) ? snapshot.Child("lname").Value.ToString() : "",
                    Email  = (snapshot.Child("email") != null) ? snapshot.Child("email").Value.ToString() : "",
                    Phone  = (snapshot.Child("phone") != null) ? snapshot.Child("phone").Value.ToString() : "",
                    City   = (snapshot.Child("city") != null) ? snapshot.Child("city").Value.ToString() : "",
                    Code   = (snapshot.Child("invitecode") != null) ? snapshot.Child("invitecode").Value.ToString() : "",
                    ImgUrl = (snapshot.Child("profile_img_url") != null) ? snapshot.Child("profile_img_url").Value.ToString() : "",
                };

                SaveToSharedPreference();
                UserFoundEvent?.Invoke(this, new EventArgs());
            }
            else
            {
                UserNotFoundEvent?.Invoke(this, new EventArgs());
            }
        }
Exemple #3
0
        public async Task TryLoginAsync(UserNotFoundReceipt e)
        {
            using (APPDbContext db = new APPDbContext())
            {
                bool b_UserVertifyEvent        = false;
                bool b_UserPwdVertifyFailEvent = false;
                bool b_UserNotFoundEvent       = false;

                await Task.Run(() =>
                {
                    string pwd_hash_aes = AssetsController.EncryptwithAppaesobj(PWD_hash);

                    var iuserlist = from t in db.Users.ToList()
                                    where t.pid == PID
                                    select t;
                    var userlist = iuserlist.ToList();
                    if (userlist.Count == 0)
                    {
                        switch (e)
                        {
                        case UserNotFoundReceipt.Create:
                            User dbuser = new User()
                            {
                                pid = PID,
                                pwd = pwd_hash_aes
                            };
                            db.Entry(dbuser).State = Microsoft.EntityFrameworkCore.EntityState.Added;
                            db.SaveChanges();
                            break;

                        case UserNotFoundReceipt.None:
                            b_UserNotFoundEvent = true;
                            return;
                        }
                    }
                    else
                    {
                        var vertifyuser = userlist[0];
                        if (vertifyuser.pid != this.PID || vertifyuser.pwd != pwd_hash_aes)
                        {
                            b_UserPwdVertifyFailEvent = true;
                        }
                    }
                    int uid = (from t in db.Users.ToList()
                               where PID == t.pid && pwd_hash_aes == t.pwd
                               select t).ToList().ElementAt(0).ID;

                    var rlist = (from t in db.Recordings.ToList()
                                 where t.uid == uid
                                 select t).ToList();

                    Core.Current.Regist(new CurrentUser(rlist, PID, PWD_hash, uid));
                    b_UserVertifyEvent = true;
                });



                if (b_UserPwdVertifyFailEvent)
                {
                    UserPwdVertifyFailEvent?.Invoke(this);
                }
                if (b_UserVertifyEvent)
                {
                    UserVertifyEvent?.Invoke(this);
                }
                if (b_UserNotFoundEvent)
                {
                    UserNotFoundEvent?.Invoke(this);
                }
            }
        }