Ejemplo n.º 1
0
        public void ConnectClient(Connection connection, Request request)
        {
            try
            {
                var    client = new Entities.Client(request.Username(), request.Password());
                string token  = logic.Login(client);

                object[] response = string.IsNullOrEmpty(token)
                    ? BuildResponse(ResponseCode.NotFound, "Client not found. Wrong username or password.")
                    : BuildResponse(ResponseCode.Ok, token);
                connection.SendMessage(response);
            }
            catch (ClientAlreadyConnectedException e)
            {
                connection.SendMessage(BuildResponse(ResponseCode.Forbidden, e.Message));
            }
        }
Ejemplo n.º 2
0
        public static byte[] SendSpawn12(Client[] Characters)
        {
            Packet p = new Packet(200);

            p.WriteByte(0);
            p.WriteByte(Characters.Length);

            for (int i = 0; i < Characters.Length; i++)
            {
                p.WriteInt(Characters[i].MyCharacter.CharacterId);
                p.WriteHexString("01 00"); // entity type, like 1 for players blabla
            }

            return p.GetWrittenBuffer(PacketIds.SendPlayerIdsSomething);
        }
Ejemplo n.º 3
0
        public static void FillDb()
        {
            using (var context = new BankDbContext())
            {
                Console.WriteLine("ConnectionString\n" + context.Database.Connection.ConnectionString);
                Console.WriteLine("DataSource\n" + context.Database.Connection.DataSource);
                Console.WriteLine("ConnectionString\n" + context.Database.Connection.Database);
                // CLEARS ALL DATA !!!
                Console.WriteLine("ALL DATA WILL BE DELETED FROM DB NOW!!! ([ENTER] TO PROCEED)");
                Console.ReadLine();
                //if (!context.Database.Exists())
                //{
                    context.Database.Delete();
                    context.Database.Create();
                //}
                context.Database.Initialize(true);//
                Console.WriteLine("Db initialized");
                Console.ReadLine();
                context.Accounts.RemoveRange(context.Accounts);
                ///Console.WriteLine("I've successfully completed first db action!");
                ///Console.ReadLine();
                context.Clients.RemoveRange(context.Clients);
                context.Credits.RemoveRange(context.Credits);
                context.CreditTypes.RemoveRange(context.CreditTypes);
                context.Payments.RemoveRange(context.Payments);
                context.Requests.RemoveRange(context.Requests);
                //context.RequestStatuses.RemoveRange(context.RequestStatuses);
                context.Users.RemoveRange(context.Users);
                context.SaveChanges();
                // CLEARS ALL DATA !!!

                //var statusRepo = new RequestStatusRepository(context);
                //var statusCreated = new RequestStatus { Status = "Created" };
                //var statusConfirmedByOperator = new RequestStatus { Status = "statusConfirmedByOperator" };
                //var statusConfirmedBySse = new RequestStatus { Status = "statusConfirmedBySecurityServiceEmployee" };
                ////var statusConfirmed = new RequestStatus { Status = "ConfirmedBy" };
                //var statusCreditProvided = new RequestStatus { Status = "statusCreditProvided" };
                //var statusDenied = new RequestStatus { Status = "Denied" };
                //statusRepo.Add(statusCreated, statusConfirmedByOperator, statusConfirmedByOperator, statusCreditProvided,statusDenied);

                //   context.SaveChanges();
                //            var confirmedByOperatorStatusId = statusCreditProvided.RequestStatusId;
                //             var createdStatusId = statusCreated.RequestStatusId;
                //             var deinedStatusId = statusDenied.RequestStatusId;

                var creditShort = new CreditType
                {
                    Name = "Easy Money",
                    //Type = "" WTF IS TYPE?????
                    TimeMonths = 12,
                    PercentPerYear = 20.0m,
                    Currency = "USD",
                    FinePercent = 40.0m,
                    MinAmount = 200,
                    MaxAmount = 2000,
                    IsAvailable = true
                };

                var creditMedium = new CreditType
                {
                    Name = "Not So Easy Money",
                    //Type = "" WTF IS TYPE?????
                    TimeMonths = 12 * 2,
                    PercentPerYear = 25.0m,
                    Currency = "USD",
                    FinePercent = 50.0m,
                    MinAmount = 200,
                    MaxAmount = 5000,
                    IsAvailable = true
                };

                var creditLong = new CreditType
                {
                    Name = "Still Money",
                    //Type = "" WTF IS TYPE?????
                    TimeMonths = 12 * 4,
                    PercentPerYear = 30.0m,
                    Currency = "USD",
                    FinePercent = 60.0m,
                    MinAmount = 200,
                    MaxAmount = 5000,
                    IsAvailable = true
                };

                var creditTypeRepo = new CreditTypeRepository(context);
                creditTypeRepo.Add(creditShort, creditLong, creditMedium);
                context.SaveChanges();
                var creditEasyId = creditShort.CreditTypeId;
                var creditMediumId = creditMedium.CreditTypeId;
                var creditLongId = creditLong.CreditTypeId;

                var admin = new User { Login = "******", Password = "******", Role = UserRole.Admin, IsActive = true };

                var ss = new User // security service employee
                { Login = "******", Password = "******", Role = UserRole.SecurityServiceEmployee, IsActive = true };

                var operator1 = new User //
                { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true };

                var operator2 = new User //
                { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true };

                var client1 = new User { Login = "******", Password = "******", Role = UserRole.Client };

                var client2 = new User { Login = "******", Password = "******", Role = UserRole.Client };

                var client3 = new User { Login = "******", Password = "******", Role = UserRole.Client };

                var userRepo = new UserRepository(context);
                userRepo.Add(admin, ss, operator1, operator2, client1, client2, client3);
                context.SaveChanges();
                var client1Id = client1.UserId;
                var client2Id = client2.UserId;
                var client3Id = client3.UserId;

                var client1Info = new Client
                {
                    UserId = client1.UserId,
                    Name = "Clientone",
                    LastName = "Clientov",
                    Patronymic = "Clientovich",
                    Birthday = new DateTime(1990, 1, 1),
                    Mobile = "+375441234567",
                    Email = "*****@*****.**",
                    PassportNo = "AB1234567",
                    PassportIdentificationNo = "4123456B124PB7",
                    PassportAuthority = "Ministry of internal affairs",
                    PassportExpirationDate = DateTime.Now.AddYears(6),
                    PlaceOfResidence = "Pushkina st.1 app.18",
                    RegistrationAddress = "Pushkina st.1 app.18"
                };

                var client2Info = new Client
                {
                    UserId = client2.UserId,
                    Name = "Clienttwo",
                    LastName = "Clientov",
                    Patronymic = "Clientovich",
                    Birthday = new DateTime(1982, 2, 2),
                    Mobile = "+375251234567",
                    Email = "*****@*****.**",
                    PassportNo = "AB1234123",
                    PassportIdentificationNo = "4125552B124PB7",
                    PassportAuthority = "Ministry of internal affairs",
                    PassportExpirationDate = DateTime.Now.AddYears(1),
                    PlaceOfResidence = "Pushkina st.2 app.7",
                    RegistrationAddress = "Pushkina st.2 app.7"
                };

                var client3Info = new Client
                {
                    UserId = client3.UserId,
                    Name = "Clientthree",
                    LastName = "Clientov",
                    Patronymic = "Clientovich",
                    Birthday = new DateTime(1973, 3, 3),
                    Mobile = "+375291234567",
                    Email = "*****@*****.**",
                    PassportNo = "AB1223331",
                    PassportIdentificationNo = "4129332B124PB3",
                    PassportAuthority = "Ministry of internal affairs",
                    PassportExpirationDate = DateTime.Now.AddYears(6),
                    PlaceOfResidence = "Pushkina st.3 app.24",
                    RegistrationAddress = "Pushkina st.3 app.24"
                };

                var clientRepo = new ClientRepository(context);
                clientRepo.Add(client1Info, client2Info, client3Info);
                context.SaveChanges();

                var request1client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = createdStatusId,
                    Status = RequestStatus.Created,
                    CreditTypeId = creditEasyId,
                    AmountOfCredit = 1000,
                    Salary = 500
                };

                var request2client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = createdStatusId,
                    Status = RequestStatus.Created,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditMediumId,
                    AmountOfCredit = 1200,
                    Salary = 500
                };

                var request3client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = confirmedByOperatorStatusId,
                    Status = RequestStatus.ConfirmedByOperator,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditLongId,
                    AmountOfCredit = 1000,
                    Salary = 500
                };

                var request4client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    Status = RequestStatus.ConfirmedByOperator, // createdStatusId,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditMediumId,
                    AmountOfCredit = 1100,
                    Salary = 500
                };
                var request5client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = createdStatusId,
                    Status = RequestStatus.CreditProvided,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditLongId,
                    AmountOfCredit = 1300,
                    Salary = 500
                };

                var request6client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = confirmedByOperatorStatusId,
                    Status = RequestStatus.CreditProvided,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditLongId,
                    AmountOfCredit = 900,
                    Salary = 500
                };
                var request7client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    Status = RequestStatus.ConfirmedBySecurityOfficer, // createdStatusId,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditLongId,
                    AmountOfCredit = 800,
                    Salary = 500
                };
                var request8client1 = new Request
                {
                    ClientId = client1Info.ClientId,
                    //RequestStatusId = confirmedByOperatorStatusId,
                    Status = RequestStatus.CreditProvided,
                    OperatorId = operator1.UserId,
                    CreditTypeId = creditMediumId,
                    AmountOfCredit = 900,
                    Salary = 500
                };

                var requestRepo = new RequestRepository(context);
                requestRepo.Add(
                    request1client1,
                    request2client1,
                    request3client1,
                    request4client1,
                    request5client1,
                    request6client1,
                    request7client1,
                    request8client1);
                context.SaveChanges();

                //var acc1 = new Account  //Bank Account
                //{
                //    ClientId = null,
                //    Balance = 40*1000*1000
                //};

                var bankAccount = new BankAccount //Bank Account
                { Balance = 40 * 1000 * 1000, Currency = "USD" };
                context.BankAccount = bankAccount;
                context.SaveChanges();

                var acc2 = new Account { ClientId = client1Info.ClientId, Balance = request2client1.AmountOfCredit };

                var accountRepo = new AccountRepository(context);
                accountRepo.Add( /*acc1,*/ acc2);
                context.SaveChanges();

                DateTime dt1 = DateTime.Now.AddDays(-(30 * 4 + 5));
                var credit1Client1 = new Credit
                {
                    AccountId = acc2.AccountId,
                    CreditTypeId = creditLong.CreditTypeId,
                    //ContractNo = 123123, //random
                    RequestId = request5client1.RequestId,
                    //AllreadyPaid = 0,
                    AmountOfPaymentPerMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12),
                    StartDate = dt1,
                    IsRepaid = false,
                    HasDelays = false,
                    CountFineFromThisDate = dt1.AddDays(30),//DateTime.UtcNow.AddDays(30), //!!! hard-coded!!!
                    AmountToCountFineFromForFirstDelayedMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12),
                    PaidForFine = 0
                };
                DateTime dt2 = DateTime.UtcNow.AddDays(-(30 * 50 + 7));
                var credit2Client1 = new Credit
                {
                    AccountId = acc2.AccountId,
                    CreditTypeId = creditLong.CreditTypeId,
                    //ContractNo = 123123, //random
                    RequestId = request6client1.RequestId,
                    //AllreadyPaid = 0,
                    AmountOfPaymentPerMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths/12),
                    StartDate = dt2,
                    IsRepaid = true,
                    HasDelays = true,
                    CountFineFromThisDate = dt2.AddDays(30), //!!! hard-coded!!!
                    AmountToCountFineFromForFirstDelayedMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12),
                    PaidForFine = 0
                };

                var credit3Client1 = new Credit
                {
                    AccountId = acc2.AccountId,
                    CreditTypeId = creditMedium.CreditTypeId,
                    //ContractNo = 123123, //random
                    RequestId = request8client1.RequestId,
                    //AllreadyPaid = 0,
                    AmountOfPaymentPerMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12),
                    StartDate = DateTime.Now,
                    IsRepaid = false,
                    HasDelays = true,
                    CountFineFromThisDate = DateTime.Now.AddDays(30), //!!! hard-coded!!!
                    AmountToCountFineFromForFirstDelayedMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12),
                    PaidForFine = 0
                };
                request5client1.Credit = credit1Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise)
                request6client1.Credit = credit2Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise)
                request8client1.Credit = credit3Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise)

                var creditRepo = new CreditRepository(context);
                creditRepo.Add(credit1Client1, credit2Client1, credit3Client1);
                context.SaveChanges();

               /*     var payment = new Payment
                {
                    OperatorId = operator1.UserId,
                    CreditId = credit1Client1.CreditId,
                    //ContractNo = credit1Client1.ContractNo,
                    Amount = 75,
                    Date = credit1Client1.StartDate.AddDays(15)
                };
                //var credit

                var payRepo = new PaymentRepository(context);
                payRepo.Add(payment);                                */
                var test = context.BankAccount;
                    //context.RequestStatuses.Where(x => x.Status.Contains("Created")).FirstOrDefault();
                //context.RequestStatuses.Add(new RequestStatus { Status = "Created" });
                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 public void AddClient(Entities.Client client)
 {
     Clients.Add(client);
 }
Ejemplo n.º 5
0
 public bool ClientExists(Entities.Client client)
 {
     return(Clients.Contains(client));
 }
Ejemplo n.º 6
0
 public ClientVM Map(Client client)
 {
     return Mapper.Map<Client, ClientVM>(client);
 }
Ejemplo n.º 7
0
        public RegistrationWindow(IUserBusinessComponent userBusinessComponent, UserRole userRole,
            IClientBusinessComponent clientBusinessComponent, Client clientToUpdate)
        {
            _userBusinessComponent = userBusinessComponent;
            _clientBusinessComponent = clientBusinessComponent;
            this._clientToUpdate = clientToUpdate;
            _role = userRole;

            InitializeComponent();

            // tab 1 setup
            textBox_Create_Login.MaxLength = UserValidation.UserNameMaxLength;
            passwordBox_Create_Password.MaxLength = UserValidation.PasswordMaxLength;
            passwordBox_Create_Password_Copy.MaxLength = UserValidation.PasswordMaxLength;

            ClientInfoTabItem.IsEnabled = false;
            ClientInfoTabItem.Visibility = Visibility.Hidden;

            // tab 2 setup
            LastNameTextBox.MaxLength = ClientValidation.LastNameMaxLength;
            NameTextBox.MaxLength = ClientValidation.NameMaxLength;
            //PatronymicTextBox.MaxLength = ClientValidation.PatronymicMaxLength;
            BirthdayDatePicker.DisplayDateStart = ClientValidation.MinBirthDate;
            BirthdayDatePicker.DisplayDateEnd = ClientValidation.MaxBirthDate;
            MobilePhoneNumberTextBox.MaxLength = ClientValidation.MobileMaxLength;
            PassportNoTextBox.MaxLength = ClientValidation.PassportNoMaxLength;
            PasswordExpirationDatePicker.DisplayDateStart = ClientValidation.MinPassportExpirationDate;
            PasswordExpirationDatePicker.DisplayDateEnd = ClientValidation.MaxPassportExpirationDate;
            PassportIdentityNoTextBox.MaxLength = ClientValidation.PassportIdentityNoMaxLength;
            PassportAuthorityTextBox.MaxLength = ClientValidation.PasswordAuthorityMaxLength;
            PlaceOfResidenceTextBox.MaxLength = ClientValidation.AddressMaxLength;
            RegistrationAddressTextBox.MaxLength = ClientValidation.AddressMaxLength;

            if (_role != UserRole.Admin) // client
            {
                roleComboBox.Visibility = Visibility.Hidden;
                roleComboBox.IsEnabled = false;
                labelRole.Visibility = Visibility.Hidden;

                button_End_Tab1.Visibility = Visibility.Hidden;
                button_End_Tab1.IsEnabled = false;
                button_Next.Visibility = Visibility.Visible;
                button_Next.IsEnabled = true;
            }
            else
            {
                if (_clientToUpdate == null)
                {

                    roleComboBox.Items.Add("Client");
                    if (_role == UserRole.Admin)
                    {
                        roleComboBox.Items.Add("Operator");
                        roleComboBox.Items.Add("Security Service Employee");
                        roleComboBox.Items.Add("Admin");
                    }
                }
                else
                {
                    roleComboBox.Items.Add("Client");
                    roleComboBox.SelectedValue = "Client";
                    roleComboBox.IsEnabled = false;
                    roleComboBox.Visibility = Visibility.Hidden;
                    labelRole.Visibility = Visibility.Hidden;

                    tabControl.SelectedIndex = 1;
                    UserInfoTabItem.IsEnabled = false;
                    UserInfoTabItem.Visibility = Visibility.Hidden;

                    ClientInfoTabItem.Visibility = Visibility.Visible;
                    ClientInfoTabItem.IsEnabled = true;

                    button_Back.Visibility = Visibility.Hidden;
                    button_Back.IsEnabled = false;

                    button_End.Content = "Apply";

                    textBox_Create_Login.Text = _clientToUpdate.Name;
                    LastNameTextBox.Text = _clientToUpdate.LastName;
                    NameTextBox.Text = _clientToUpdate.Name;
                    //PatronymicTextBox.Text = _clientToUpdate.Patronymic;
                    BirthdayDatePicker.SelectedDate = _clientToUpdate.Birthday;
                    MobilePhoneNumberTextBox.Text = _clientToUpdate.Mobile;
                    EmailTextBox.Text = _clientToUpdate.Email;
                    PassportNoTextBox.Text = _clientToUpdate.PassportNo;
                    PasswordExpirationDatePicker.SelectedDate = _clientToUpdate.PassportExpirationDate;
                    PassportIdentityNoTextBox.Text = _clientToUpdate.PassportIdentificationNo;
                    PassportAuthorityTextBox.Text = _clientToUpdate.PassportAuthority;
                    PlaceOfResidenceTextBox.Text = _clientToUpdate.PlaceOfResidence;
                    RegistrationAddressTextBox.Text = _clientToUpdate.RegistrationAddress;
                }
            }
        }