Esempio n. 1
0
        public void CustomerCountTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context  = cRUDTestDBContextProvider.GetContext();
            var customer = new Customer {
                CustomerId = 1, SupportRepId = 1, FirstName = "TestFirst", LastName = "TestLast", Email = "Test"
            };
            var customer2 = new Customer {
                CustomerId = 2, FirstName = "Test2First", LastName = "Test2Last", Email = "2Test"
            };
            var employee = new Employee {
                EmployeeId = 1, FirstName = "TesteFirst", LastName = "TesteLast", Email = "eTest"
            };

            context.Add(customer);
            context.Add(customer2);
            context.Add(employee);
            context.SaveChanges();

            EmployeeBE employeeBE = new EmployeeBE(cRUDTestDBContextProvider);

            employeeBE.Load(1);
            Assert.IsTrue(employeeBE.CustomerCount == 1);

            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);

            customerBE.Load(2);
            employeeBE.AddToCustomer(customerBE);
            customerBE.Save();

            EmployeeBE employeeBE2 = new EmployeeBE(cRUDTestDBContextProvider);

            employeeBE2.Load(1);
            Assert.IsTrue(employeeBE2.CustomerCount == 2);
        }
        public void InvoiceCountTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var invoiceInvoiceCountTest = new Invoice {
                InvoiceId = 1, CustomerId = 1
            };
            var customerInvoiceCountTest = new Customer {
                CustomerId = 1
            };

            context.Add(invoiceInvoiceCountTest);
            context.Add(customerInvoiceCountTest);
            context.SaveChanges();

            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);

            customerBE.Load(1);
            Assert.IsTrue(customerBE.InvoiceCount == 1);

            InvoiceBE invoiceBE = new InvoiceBE(cRUDTestDBContextProvider);

            invoiceBE.New();
            customerBE.AddToInvoice(invoiceBE);
            invoiceBE.Save();

            CustomerBE customerBE2 = new CustomerBE(cRUDTestDBContextProvider);

            customerBE2.Load(1);
            Assert.IsTrue(customerBE2.InvoiceCount == 2);
        }
Esempio n. 3
0
        public void AddToCustomersTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context  = cRUDTestDBContextProvider.GetContext();
            var customer = new Customer {
                CustomerId = 1, FirstName = "TestFirst", LastName = "TestLast", Email = "Test"
            };
            var employee = new Employee {
                EmployeeId = 1, FirstName = "TesteFirst", LastName = "TesteLast", Email = "eTest"
            };

            context.Add(customer);
            context.Add(employee);
            context.SaveChanges();

            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);
            EmployeeBE employeeBE = new EmployeeBE(cRUDTestDBContextProvider);

            employeeBE.Load(1);
            customerBE.Load(1);
            employeeBE.AddToCustomer(customerBE);
            customerBE.Save();

            employeeBE.Load(1);
            var customerBECollection = employeeBE.GetCustomers();

            Assert.IsTrue(customerBECollection.First().Id == 1);
            Assert.IsTrue(customerBECollection.First().SupportRepId == 1);
        }
Esempio n. 4
0
        public List <CustomerBE> GetAllCustomers()
        {
            List <CustomerBE> list = new List <CustomerBE>();

            _mDataAcess.Open();
            try
            {
                string      sql    = "select * from Customer";
                IDataReader reader = _mDataAcess.GetReader(sql);
                while (reader.Read())
                {
                    CustomerBE customer = new CustomerBE();
                    customer.CustomerId     = reader.GetInt32(0);
                    customer.CustomerName   = reader.GetString(1);
                    customer.CustomerGender = reader.GetBoolean(2);
                    int       addressId = reader.GetInt32(3);
                    AddressBE address   = (new AddressDA()).GetById(addressId);
                    customer.Address = address;
                    list.Add(customer);
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", e);
            }
            finally
            {
                _mDataAcess.Close();
            }
            return(list);
        }
        public void AddToInvoiceTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var customerAddToInvoiceTest = new Customer {
                CustomerId = 1
            };
            var invoiceAddToInvoiceTest = new Invoice {
                InvoiceId = 1, Total = 20
            };

            context.Add(customerAddToInvoiceTest);
            context.Add(invoiceAddToInvoiceTest);
            context.SaveChanges();

            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);
            InvoiceBE  invoiceBE  = new InvoiceBE(cRUDTestDBContextProvider);

            invoiceBE.Load(1);
            customerBE.Load(1);
            customerBE.AddToInvoice(invoiceBE);
            invoiceBE.Save();

            customerBE.Load(1);
            var InvoiceBECollection = customerBE.GetInvoices().Where(p => p.Id == 1);

            Assert.IsTrue(InvoiceBECollection.First().Id == 1);
            Assert.IsTrue(InvoiceBECollection.First().CustomerID == 1);
        }
Esempio n. 6
0
        public void GetAllTripsTest()
        {
            CustomerBE cbe             = new CustomerBE();
            List <Contract.dto.Trip> l = cbe.GetAllTrips();

            Assert.AreNotEqual(0, l.Count);
        }
        public void GetInvoicesTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var invoiceGetInvoicesTest = new Invoice {
                InvoiceId = 1, CustomerId = 1, Total = 10
            };
            var customerGetInvoicesTest = new Customer {
                CustomerId = 1
            };
            var customer2GetInvoicesTest = new Customer {
                CustomerId = 2
            };

            context.Add(invoiceGetInvoicesTest);
            context.Add(customerGetInvoicesTest);
            context.Add(customer2GetInvoicesTest);
            context.SaveChanges();

            CustomerBE customerBE  = new CustomerBE(cRUDTestDBContextProvider);
            CustomerBE customerBE2 = new CustomerBE(cRUDTestDBContextProvider);

            customerBE.Load(1);
            customerBE2.Load(2);
            var invoiceBECollection = customerBE.GetInvoices();

            Assert.IsTrue(invoiceBECollection.First().GetType() == typeof(InvoiceBE));
            Assert.IsTrue(invoiceBECollection.First().Total == 10);
            Assert.IsTrue(invoiceBECollection.First().Id == 1);
            Assert.IsTrue(customerBE2.GetInvoices().IsNullOrEmpty());
        }
Esempio n. 8
0
        public List <CustomerBE> GetAllCustomerType()
        {
            List <CustomerBE> customersType = new List <CustomerBE>();

            using (_connection = new SqlConnection(_connectionString))
            {
                var        query   = "SELECT * FROM CustomerType";
                SqlCommand command = new SqlCommand(query, _connection);
                try
                {
                    _connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        CustomerBE customerType = new CustomerBE();
                        customerType.CustomerTypeID   = Convert.ToInt32(reader["CustomerTypeID"]);
                        customerType.CustomerTypeName = Convert.ToString(reader["CustomerTypeName"]);
                        //Adding object to the list
                        customersType.Add(customerType);
                    }
                    reader.Close();
                    return(customersType);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Translate customerDE to customerBE
 /// </summary>
 /// <param name="customerDE"></param>
 /// <returns></returns>
 public CustomerBE Translate(Customer customerDE)
 {
     if (customerDE != null)
     {
         CustomerBE customerBE = new CustomerBE()
         {
             CustomerId     = customerDE.CustomerId,
             CustomerName   = customerDE.CustomerName,
             CustomerGender = customerDE.CustomerGender,
             Address        = new AddressBE()
             {
                 AddressId     = customerDE.Address.AddressId,
                 Country       = customerDE.Address.Country,
                 Province      = customerDE.Address.Province,
                 City          = customerDE.Address.City,
                 DetailAddress = customerDE.Address.Address1,
             },
         };
         return(customerBE);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 10
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Proxy  service = new Proxy();
            string id      = this.labId.Text;

            string     name      = this.txCustomerName.Text.ToString().Trim();
            int        genderInt = Convert.ToInt32(this.rblGender.SelectedValue);
            bool       gender    = genderInt == 1 ? true : false;
            int        addressId = Convert.ToInt32(this.dropListAddresses.SelectedValue);
            CustomerBE customer  = new CustomerBE();

            customer.CustomerName   = name;
            customer.CustomerGender = gender;
            AddressBE address = new AddressBE();

            address.AddressId     = addressId;
            address.City          = "City";
            address.Country       = "Country";
            address.DetailAddress = "Detail";
            address.Province      = "Province";
            customer.Address      = address;

            if (id != "")
            {
                customer.CustomerId = Convert.ToInt32(id);
                service.UpdateCustomer(customer);
            }
            else
            {
                service.InsertCustomer(customer);
            }
            Response.Redirect("CustomerList.aspx");
        }
Esempio n. 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Proxy service = new Proxy();

            if (!IsPostBack)
            {
                this.dropListAddresses.DataSource     = service.GetAllAddresses();// Post back
                this.dropListAddresses.DataTextField  = "Country";
                this.dropListAddresses.DataValueField = "AddressId";
                this.dropListAddresses.DataBind();
            }


            string id = Request.QueryString["id"];

            if (id != null && this.labMethod.Text == "")
            {
                CustomerBE customer = service.GetCustomerById(Convert.ToInt32(id));
                this.txCustomerName.Text = customer.CustomerName;
                if (customer.CustomerGender)
                {
                    this.rblGender.SelectedValue = "1";
                }
                else
                {
                    this.rblGender.SelectedValue = "0";
                }
                this.dropListAddresses.SelectedValue = customer.Address.AddressId.ToString();
                this.btnCreateNewCustomer.Text       = "Update";
                this.labId.Text     = id;
                this.labMethod.Text = "Update";
            }
        }
Esempio n. 12
0
        public CustomerBE GetById(int id)
        {
            CustomerBE customer = new CustomerBE();

            _mDataAcess.Open();
            try
            {
                string         sql    = "select * from Customer where CustomerId=@CustomerId";
                QueryParameter p      = new QueryParameter(Id, id, DbType.Int32);
                IDataReader    reader = _mDataAcess.GetReader(sql, p);
                while (reader.Read())
                {
                    customer.CustomerId     = id;
                    customer.CustomerName   = reader.GetString(1);
                    customer.CustomerGender = reader.GetBoolean(2);
                    int       addressId = reader.GetInt32(3);
                    AddressBE address   = _mAddressDA.GetById(addressId);
                    customer.Address = address;
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", e);
            }
            finally
            {
                _mDataAcess.Close();
            }
            return(customer);
        }
Esempio n. 13
0
        public bool Update(CustomerBE customer)
        {
            bool result = true;

            _mDataAcess.Open();
            try
            {
                string           sql  = "update Customer set CustomerName=@CustomerName, CustomerGender=@CustomerGender, AddressId=@AddressId where CustomerId=@CustomerId";
                QueryParameter[] list = new QueryParameter[4];

                list[0] = new QueryParameter(Name, customer.CustomerName, DbType.String);
                list[1] = new QueryParameter(Gender, customer.CustomerGender, DbType.Boolean);
                list[2] = new QueryParameter(AddressId, customer.Address.AddressId, DbType.Int32);
                list[3] = new QueryParameter(Id, customer.CustomerId, DbType.Int32);
                int i = _mDataAcess.ExecuteNonQuery(sql, list);
                if (i == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", e);
            }
            finally
            {
                _mDataAcess.Close();
            }
            return(result);
        }
Esempio n. 14
0
        public void GetAllVehiclesTest()
        {
            CustomerBE cbe = new CustomerBE();

            List <Contract.dto.Vehicle> l = cbe.GetAllVehicles();

            Assert.IsTrue(l.Count >= 1);
        }
Esempio n. 15
0
        /// <summary>
        /// Inserts the customer.  --Robin
        /// </summary>
        /// <param name="customerBE">The customer BE.</param>
        /// <returns></returns>
        public bool InsertCustomer(CustomerBE customerBE)
        {
            InsertCustomerRequest request = new InsertCustomerRequest();

            request.MyCustomer = customerBE;
            InsertCustomerResponse response = MyChannelFactory.CreateChannel().InsertCustomer(request);

            return(!response.IsFailed);
        }
Esempio n. 16
0
        public void CreateCustomerTest()
        {
            CustomerBE cbe = new CustomerBE();

            Contract.dto.Customer c = UnitTest.TestHelpers.randomCustomer();
            c.CustomerId = 0;

            Assert.IsTrue(cbe.CreateCustomer(c));
        }
Esempio n. 17
0
        /// <summary>
        /// Translate customerBE to customerDE
        /// </summary>
        /// <param name="customerBE"></param>
        /// <returns></returns>
        public Customer Translate(CustomerBE customerBE)
        {
            Customer customerDE = new Customer();

            customerDE.CustomerId     = customerBE.CustomerId;
            customerDE.CustomerName   = customerBE.CustomerName;
            customerDE.CustomerGender = customerBE.CustomerGender;
            customerDE.AddressId      = customerBE.Address.AddressId;
            return(customerDE);
        }
Esempio n. 18
0
        public void CreateCustomerReservationTest()
        {
            CustomerBE cbe = new CustomerBE();

            Contract.dto.Reservation r = cbe.CreateCustomerReservation(
                UnitTest.TestHelpers.randomTrip(),
                UnitTest.TestHelpers.randomCustomer(),
                24.3,
                UnitTest.TestHelpers.GenerateRandomId(1, 10),
                UnitTest.TestHelpers.randomVehicle()
                );
            Assert.AreNotEqual(0, r.ReservationId);
        }
        public void SaveWithoutIdTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);

            customerBE.New();
            customerBE.FirstName = "TestFirstName";
            customerBE.LastName  = "TestLastName";
            customerBE.Email     = "*****@*****.**";
            customerBE.Save();

            Assert.IsTrue(customerBE.Id != default);
        }
Esempio n. 20
0
        public ActionResult Registration(CustomerBE s)
        {
            int res = ob.Registration(s);

            if (res > 0)
            {
                ViewData["status"] = " Registered successfully ";
            }
            else
            {
                ViewData["status"] = "CustID already Exists";
            }
            return(View());
        }
Esempio n. 21
0
        /// <summary>
        /// Insert a customer
        /// </summary>
        /// <param name="dbEntity"> Database Entity Container</param>
        /// <param name="customerBE">Customer DataEntity</param>
        public bool Insert(TTAEntityContainer dbEntity, CustomerBE customerBE)
        {
            dbEntity.AddToCustomers((new CustomerTranslator()).Translate(customerBE));
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 22
0
 public Customer(CustomerBE c)
 {
     Id       = c.Id;
     Name     = c.Name;
     Address  = c.Address;
     ZipCode  = c.ZipCode;
     City     = c.City;
     Email    = c.Email;
     Phone    = c.Phone;
     Accounts = new List <BankAccount>();
     foreach (BankAccountBE acc in c.Accounts)
     {
         Accounts.Add(new BankAccount(acc));
     }
 }
Esempio n. 23
0
        public async Task <CustomerBE> RecuperarPorDni(string nroDocumento)
        {
            CustomerBE customerBE = null;

            var res = await(from x in _clienteContext.Cliente
                            where x.NroDocumento == nroDocumento
                            select x).FirstOrDefaultAsync();

            if (res != null)
            {
                customerBE = new CustomerBE(res);
            }

            return(customerBE);
        }
Esempio n. 24
0
        public async Task <CustomerBE> RecuperarTitularIdCuenta(int idCuenta)
        {
            CustomerBE customerBE = null;

            var res = await(from x in _clienteContext.Cuenta.Include("Cliente")
                            where x.IdCuenta == idCuenta
                            select x.Cliente).FirstOrDefaultAsync();

            if (res != null)
            {
                customerBE = new CustomerBE(res);
            }

            return(customerBE);
        }
Esempio n. 25
0
        public void GetCustomerByLoginTest()
        {
            CustomerBE cbe = new CustomerBE();

            Contract.dto.Customer c = UnitTest.TestHelpers.randomCustomer();
            c.CustomerId = 1;
            c.Mail       = UnitTest.TestHelpers.RandomWords(UnitTest.TestHelpers.GenerateRandomId(5, 15));
            c.Password   = UnitTest.TestHelpers.RandomWords(UnitTest.TestHelpers.GenerateRandomId(5, 15));
            cbe.CreateCustomer(c);

            Contract.dto.Customer c2 = cbe.GetCustomerByLogin(c.Mail, c.Password);

            /// This might work, but because we use random mail and password, it only works sometimes (Most of the time)
            Assert.AreEqual(c.CustomerId, c2.CustomerId);
        }
Esempio n. 26
0
        public async Task <CustomerBE> RecuperarPorId(int id)
        {
            //
            CustomerBE customerBE = null;

            var res = await(from x in _clienteContext.Cliente
                            where x.IdCliente == id
                            select x).FirstOrDefaultAsync();

            if (res != null)
            {
                customerBE = new CustomerBE(res);
            }

            return(customerBE);
        }
Esempio n. 27
0
        public void CreateDefaultBankAcccount(CustomerBE cbe)
        {
            BankAccount acc = new BankAccount()
            {
                AccountNumber = nextAccNumber++,
                Balance       = 0.0,
                InterestRate  = BankAccount.DEFAULT_INTERESTRATE,
                Customers     = new List <Customer>()
                {
                    new Customer(cbe)
                }
            };


            AccountsRepo.Add(acc);
        }
Esempio n. 28
0
        /// <summary>
        /// Updates the customer.  --Robin
        /// </summary>
        /// <param name="customerBE">The customer BE.</param>
        /// <returns></returns>
        public bool UpdateCustomer(CustomerBE customerBE)
        {
            UpdateCustomerRequest request = new UpdateCustomerRequest();

            request.MyCustomer = customerBE;
            UpdateCustomerResponse response = MyChannelFactory.CreateChannel().UpdateCustomer(request);

            if (response.IsFailed)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", new Exception(response.Message));
                log.Fatal("fatal", new Exception(response.Message));
                throw new Exception("We have a error!");
            }
            return(true);
        }
Esempio n. 29
0
        /// <summary>
        /// Inserts the customer.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="gender">if set to <c>true</c> [gender].</param>
        /// <param name="addressId">The address id.</param>
        public void InsertCustomer()
        {
            CustomerBE customer = new CustomerBE();

            customer.CustomerName   = View.CustomerName;
            customer.CustomerGender = View.CustomerGender;
            AddressBE address = new AddressBE();

            address.AddressId     = View.CustomerAddressId;
            address.City          = "City";
            address.Country       = "Country";
            address.DetailAddress = "Detail";
            address.Province      = "Province";
            customer.Address      = address;
            _controller.InsertCustomer(customer);
        }
        public void LoadValidIdTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context  = cRUDTestDBContextProvider.GetContext();
            var customer = new Customer
            {
                CustomerId   = 1,
                FirstName    = "TestFirstName",
                LastName     = "TestLastName",
                Email        = "*****@*****.**",
                Company      = "TestCompany",
                Address      = "123 Test Address",
                City         = "TestCity",
                State        = "TestState",
                Country      = "TestCountry",
                PostalCode   = "TestPC",
                Phone        = "TestPhone",
                Fax          = "TestFax",
                SupportRepId = 1
            };
            var employeeLoadValidIdTest = new Employee {
                EmployeeId = 1, FirstName = "TestEmployeeFirst", LastName = "TestEmployeeLast"
            };

            context.Add(customer);
            context.Add(employeeLoadValidIdTest);
            context.SaveChanges();

            CustomerBE customerBE = new CustomerBE(cRUDTestDBContextProvider);

            customerBE.Load(1);
            Assert.IsTrue(customerBE.Id == 1);
            Assert.IsTrue(customerBE.FirstName == "TestFirstName");
            Assert.IsTrue(customerBE.LastName == "TestLastName");
            Assert.IsTrue(customerBE.Company == "TestCompany");
            Assert.IsTrue(customerBE.Address == "123 Test Address");
            Assert.IsTrue(customerBE.City == "TestCity");
            Assert.IsTrue(customerBE.State == "TestState");
            Assert.IsTrue(customerBE.Country == "TestCountry");
            Assert.IsTrue(customerBE.PostalCode == "TestPC");
            Assert.IsTrue(customerBE.Phone == "TestPhone");
            Assert.IsTrue(customerBE.Fax == "TestFax");
            Assert.IsTrue(customerBE.Email == "*****@*****.**");
            Assert.IsTrue(customerBE.SupportRepId == 1);
        }