public static Account AccountModelToEntity(AccountModel model)
 {
     Account entity = new Account();
     entity.Username = model.Username;
     //entity.Room = RoomModelToEntity(model.Room);
     return entity;
 }
Beispiel #2
0
        public bool CreateAccount(Account account)
        {
            if (GetAccountByLogin(account.Login, true) != null)
                return false;

            account.Id = Guid.NewGuid();
            account.CreatedTime = DateTime.Now;

            if (account.Avatar == null)
                account.Avatar = _basixAvatar;
            if (account.City == null)
                account.City = _basixCity;
            if (account.Country == null)
                account.Country = _basixCountry;
            if (account.MimeType == null)
                account.MimeType = _basixMimeType;
            _data.CreateAccount(account);
            return true;
        }
Beispiel #3
0
        public bool CreateAccount(Account account)
        {
            string queryString =
                "INSERT INTO accounts (accountid, login, name, mail, password, createdtime, country, city, photo, mimetype) " +
                "VALUES (@accountid, @login, @name, @mail, @password, @createdtime, @country, @city, @photo, @mimetype); " +
                "INSERT INTO UsersRoles (id, RoleId, accountid) " +
                "VALUES(@id, @RoleId, @accountid)";
            
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                var command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("accountid", account.Id);
                command.Parameters.AddWithValue("login", account.Login);
                command.Parameters.AddWithValue("name", account.Login);
                command.Parameters.AddWithValue("mail", account.Email);
                command.Parameters.AddWithValue("password", account.Password);
                command.Parameters.AddWithValue("createdtime", account.CreatedTime);
                command.Parameters.AddWithValue("id", Guid.NewGuid());
                command.Parameters.AddWithValue("RoleId", 1);
                command.Parameters.AddWithValue("country", account.Country);
                command.Parameters.AddWithValue("city", account.City);
                command.Parameters.AddWithValue("photo", account.Avatar);
                command.Parameters.AddWithValue("mimetype", account.MimeType);

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return true;
        }
        /// <summary>
        /// Adds songs to the database
        /// </summary>
        /// <param name="model">SongModel of song being added</param>
        public void Add(SongModel model)
        {
            try
            {
                Account account;

                //Convert the SongModel into an entity to be pushed to the database.
                Song entity = ModelConversions.SongModelToEntity(model);

                //If there is an account that matches the given username, set account equal to it.
                if (_context.Accounts.Any(a => a.Username == model.Username))
                {
                    account = _context.Accounts.First(a => a.Username == model.Username);
                }
                //Else, create an Account with the username
                else
                {
                    account = new Account() { Username = model.Username };
                }

                //Add the account association to the song, and push the song to the database
                entity.Accounts.Add(account);
                _context.Songs.Add(entity);
                _context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
        }
Beispiel #5
0
 public void CreateAdmin(Account account)
 {
     account.Avatar = _basixAvatar;
     account.CreatedTime = DateTime.Now;
     account.Id = Guid.NewGuid();
     account.MimeType = _basixMimeType;
     var hash = this.GetSHA256(account.Password);
     account.Password = hash;
     _data.CreateAdmin(account);
 }
 public void Create(Account model)
 {
     accountRepository.Create(model);
 }
Beispiel #7
0
 public virtual string GetMessage(Account account)
 {
     return string.Empty;
 }
        static void Main(string[] args)
        {
            var context = new BestPracticesDbContext();

            context.Database.Initialize(true);

            var account = new Account()
            {
                AccountName = "El Al Cargo",
                Settings = new Settings()
                {
                    MaxPickupsPerCar = 3,
                    MaxTripDuration = 75,
                    MinPickupsPerCar = 2
                }
            };
            context.Accounts.Add(account);
            context.SaveChanges();

            var user = new User()
            {
                Username = "******",
                LastLogin = DateTime.Now,
                Email = "*****@*****.**",
                AccessibleAccounts = new List<AccountUsers>()
                        {
                            new AccountUsers()
                            {
                                AuthorizationLevel = new AuthorizationLevel()
                                {
                                    Description = "admin"
                                },
                                AccountId = account.Id
                            }
                        }
            };
            context.Users.Add(user);
            context.SaveChanges();

            var destinationAddress = new Address()
            {
                IsArchived = false,
                FirstLine = "502 Shoreham Rd",
                SecondLine = "London Heatrow Airport , Hounslow",
                PostCode = "TW6 3UA",
                City = "London",
                Country = "United Kingdom"
            };
            context.Addresses.Add(destinationAddress);
            context.SaveChanges();

            var contactAddress = new Address()
            {
                FirstLine = "6 Bridgeman House",
                SecondLine = "Pump House Crescent",
                PostCode = "TW8 0FX",
                City = "London",
                Country = "United Kingdom",
            };
            context.Addresses.Add(contactAddress);
            context.SaveChanges();

            var contact = new Contact()
            {
                FirstName = "Chen",
                LastName = "Keren Kaminsky",
                Email = "*****@*****.**",
                Phone = "07474772070",
                IsArchived = false,
                PrimaryAddressId = contactAddress.Id
            };
            context.Contacts.Add(contact);
            context.SaveChanges();

            contact.ContactAddresses.Add(new ContactAddresses()
            {
                Contact = contact,
                Address = contactAddress
            });

            var mailingContact = new Contact()
            {
                FirstName = "Dina",
                LastName = "Barel",
                Email = "*****@*****.**",
                Phone = "0208000000",
                IsArchived = false,
                PrimaryAddressId = null,
            };
            context.Contacts.Add(mailingContact);
            context.SaveChanges();

            var mailingList = new MailingList()
            {
                Name = "Default"
            };
            context.MailingLists.Add(mailingList);
            context.SaveChanges();

            mailingList.MailingListContacts.Add(new MailingListContact()
            {
                Contact = mailingContact,
                MailingList = mailingList
            });

            account.AccountDestinations.Add(new AccountDestinations()
            {
                Account = account,
                Address = destinationAddress,
                AddressNickname = "Cargo Warehouse"
            });

            account.MailingLists.Add(mailingList);

            context.SaveChanges();




            var storedAccount = context.Accounts.FirstOrDefault();

            if (storedAccount != null)
            {
                Console.WriteLine(storedAccount.AccountName);
                Console.WriteLine("Settings:\n{0}\n{1}\n{2}", storedAccount.Settings.MaxPickupsPerCar, storedAccount.Settings.MaxTripDuration,
                    storedAccount.Settings.MinPickupsPerCar);
                Console.WriteLine("Contacts:");
                foreach (var cnt in storedAccount.Contacts)
                {
                    Console.WriteLine(cnt.FirstName + " " + cnt.LastName);
                    Console.WriteLine("Primary Address:");
                    Console.WriteLine(cnt.ContactAddresses.FirstOrDefault(a => a.Address.Id == cnt.PrimaryAddressId).Address.FirstLine);
                }
                Console.WriteLine("Destinations: ");
                foreach (var dst in storedAccount.AccountDestinations)
                {
                    Console.WriteLine(dst.AddressNickname + ": " + dst.Address.FirstLine);
                }
                Console.WriteLine("Mailing Lists:");
                foreach (var mailList in storedAccount.MailingLists)
                {
                    Console.WriteLine(mailList.Name + ": ");
                    foreach (var mcnt in mailList.MailingListContacts)
                    {
                        Console.WriteLine(mcnt.Contact.FirstName + ": " + mcnt.Contact.Email);
                    }
                }
            }
            else
            {
                Console.WriteLine("No recordes found");
            }


            Console.WriteLine("Done! Press any key to exit.");
            Console.ReadKey();
        }
Beispiel #9
0
 public static void CreateAdmin(Account account)
 {            
     _logic.CreateAdmin(account);
 }
Beispiel #10
0
 public void VD(string c)
 {
     Account acc = new Account();
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " changed the goal target by " + Delta + " at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }
Beispiel #12
0
        public ActionResult Register(RegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var acc = Adapter.CheckAccount(model.Login);
            if (acc != null && acc.Login != null)
            {
                ModelState.AddModelError("Login", "Пользователь с таким логином уже существует!");
            }

            //Чтобы показать новые ошибки
            if (!ModelState.IsValid)
            {
                if (Request.IsAjaxRequest())
                {
                    return PartialView(model);
                }
                return View(model);
            }

            Account account = new Account
            {
                Login = model.Login,
                Password = Adapter.GetSHA256(model.Password),
                Email = model.Email
            };

            bool success = Adapter.CreateUserAndAccount(account);
            if (success)
            {
                FormsAuthentication.SetAuthCookie(account.Login, true);
            }

            return RedirectToAction("Index", "Home");
        }
Beispiel #13
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();
            }
        }
 public void AddInvitedAccount(Account account)
 {
     accountRepository.AddInvitedAccount(account);
 }
 public void Update(Account model)
 {
     accountRepository.Update(model);
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " changed the description at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " updated a task title at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " marked a task as " + (IsComplete ? "complete" : "incomplete") + " at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }
Beispiel #19
0
 public static bool CreateUserAndAccount(Account account)
 {
     if (_logic.CreateAccount(account))
         return true;
     return false;
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " created the goal at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }
 public override string GetMessage(Account account)
 {
     return account.FullName + " changed the current number to " + Number + " at " + EventDate.ToString("MMMM d, yyyy H:mm tt");
 }