コード例 #1
0
 public void RefreshEmployeesList()
 {
     foreach (var employee in _employeesRepository.GetAll())
     {
         employeesListBox.Items.Add(employee);
     }
 }
コード例 #2
0
        private bool CheckInput()
        {
            if (employeeFirstName.Text == "" || employeeLastName.Text == "" || employeeOib.Text == "" ||
                employeeRole.SelectedItem == null)
            {
                MessageBox.Show(@"One or more fields empty!", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (employeeFirstName.Text.Length + employeeLastName.Text.Length > 25)
            {
                MessageBox.Show($@"Employee's full name is too long, contains: {employeeFirstName.Text.Length + employeeLastName.Text.Length} characters! Limit: 25", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            var counter = 0;

            foreach (var employee in _employeesRepository.GetAll())
            {
                if (employeeOib.Text == employee.Oib)
                {
                    counter++;
                }
            }

            var isOibChanged = _selectedEmployee == null;

            if (!isOibChanged)
            {
                isOibChanged = _selectedEmployee.Oib != employeeOib.Text;
            }

            if (isOibChanged && counter > 0 || !isOibChanged && counter > 1)
            {
                MessageBox.Show($@"Employee with {employeeOib.Text} OIB already exists!", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (employeeOib.Text.TrimAndRemoveWhiteSpaces().Length < 11)
            {
                MessageBox.Show($@"Employee OIB doesn't have enough characters, contains: {employeeOib.Text.TrimAndRemoveWhiteSpaces().Length}! Must have: 11", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            var birthday = Convert.ToDateTime(employeeBirthday.Text);


            if (DateTime.Now - birthday >= DateTime.Now - DateTime.Now.AddYears(-62)) // Let's say that 62 years is limit for working age
            {
                MessageBox.Show(@"Employee is older than 62 years old", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (DateTime.Now - birthday >= DateTime.Now - DateTime.Now.AddYears(-18))
            {
                return(true);
            }
            MessageBox.Show(@"Employee is younger than 18 years old", @"Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return(false);
        }
コード例 #3
0
        public void Employees_Create()
        {
            var repository = new EmployeesRepository();
            //Employees employee = new Employees()
            //{
            //    Name = "洪識超",
            //    Phone = "0123456789",
            //    HireDate = new DateTime(1996, 06, 01),
            //};
            //repository.Create(employee);
            //Employees employee1 = new Employees()
            //{
            //    Name = "簡愷祐",
            //    Phone = "0123456789",
            //    HireDate = new DateTime(1996, 01, 29),
            //};
            //repository.Create(employee1);
            //Employees employee2 = new Employees()
            //{
            //    Name = "黃思源",
            //    Phone = "0123456789",
            //    HireDate = new DateTime(1996, 02, 16),
            //};
            //repository.Create(employee2);
            var employees = repository.GetAll(connection);

            Assert.IsTrue(employees.Count() > 0);
        }
コード例 #4
0
ファイル: TestGetAll.cs プロジェクト: BS-MVC-Team/E_Commerce
        public void Test_GetAll_Employee()
        {
            var repository = new EmployeesRepository();
            var employee   = repository.GetAll();

            Assert.IsTrue(employee.Count() == 0);
        }
コード例 #5
0
        public void EmployeesRepositoryTests_GetAll()
        {
            EmployeesRepository repository = new EmployeesRepository();
            var result = repository.GetAll();

            Assert.IsTrue(result.Count() == 3);
        }
コード例 #6
0
        public ActionResult Index()
        {
            EmployeesRepository repo  = new EmployeesRepository();
            List <Employee>     items = repo.GetAll();

            ViewData["items"] = items;

            return(View());
        }
コード例 #7
0
        private void RefreshList()
        {
            employeeProjectListBox.Items.Clear();

            if (_option == "1")
            {
                foreach (var project in _projectsRepository.GetAll())
                {
                    employeeProjectListBox.Items.Add(project);
                }
            }
            else
            {
                foreach (var employee in _employeesRepository.GetAll())
                {
                    employeeProjectListBox.Items.Add(employee);
                }
            }
        }
コード例 #8
0
        public ActionResult Create()
        {
            ViewBag.Status = new SelectList(
                new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Not Started", Value = "Not Started"
                },
                new SelectListItem {
                    Text = "Delayed", Value = "Delayed"
                },
                new SelectListItem {
                    Text = "Completed", Value = "Completed"
                },
                new SelectListItem {
                    Text = "In the Process", Value = "In the Process"
                },
            }, "Value", "Text");

            ViewBag.Emp = new SelectList(repemp.GetAll(), "Id", "Last_name");

            return(View());
        }
コード例 #9
0
        public async Task <List <EmployeeDto> > GetEmployees()
        {
            List <EmployeeDto> employees = new List <EmployeeDto>();

            var empls = await repository.GetAll();

            //Automapper
            employees = empls.Select(s => new EmployeeDto
            {
                id              = s.id,
                name            = s.name,
                roleId          = s.roleId,
                roleDescription = s.roleDescription,
                roleName        = s.roleName,
                hourlySalary    = s.hourlySalary,
                monthlySalary   = s.monthlySalary,
                annualSalary    = SalaryFactory.Get((ContractEmun)Enum.Parse(typeof(ContractEmun), s.contractTypeName), s.hourlySalary.Value, s.monthlySalary.Value)
            }).ToList();

            return(employees);
        }
コード例 #10
0
 public ActionResult <IEnumerable <Employee> > Get()
 {
     return(_employeesRepository.GetAll());
 }
コード例 #11
0
 // GET: Funcionarios
 public ActionResult Index()
 {
     return(View(_repository.GetAll()));
 }
コード例 #12
0
        public JsonResult Order(string name, string phone, string address, string memberID, decimal totalPrice)
        {
            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(phone) || string.IsNullOrWhiteSpace(address))
            {
                return(Json("填空區不可有空白"));
            }
            else
            {
                if (Regex.Match(name, @"[\u3000-\u9FA5\x20]{2,4}").Success)
                {
                    if (Regex.Match(phone, @"(\(?\d{3,4}\)?)?[\s-]?\d{7,8}[\s-]?\d{0,4}").Success)
                    {
                        ShoppingCartRepository  shoppingCartRepository  = new ShoppingCartRepository();
                        OrdersRepository        ordersRepository        = new OrdersRepository();
                        EmployeesRepository     employeesRepository     = new EmployeesRepository();
                        ProductFormatRepository productFormatRepository = new ProductFormatRepository();
                        OrderDetailsRepository  orderDetailsRepository  = new OrderDetailsRepository();
                        ProductRepository       productRepository       = new ProductRepository();
                        var employees    = employeesRepository.GetAll();
                        var randomNumber = new Random().Next(0, employees.Count());


                        Orders orders = new Orders()
                        {
                            EmployeeID  = employees.ElementAt(randomNumber).EmployeeID,
                            MemberID    = memberID,
                            ShipName    = name,
                            ShipAddress = address,
                            ShipPhone   = phone,
                            OrderDate   = DateTime.Now,
                            Status      = "未送貨",
                            TotalPrice  = totalPrice
                        };

                        ordersRepository.Create(orders);
                        Procedure.Procedure procedure = new Procedure.Procedure();
                        var orderTempID = procedure.FindOrderID(memberID);

                        var shoppingCart = shoppingCartRepository.FindByMemberID(memberID);
                        Stack <OrderDetails> orderData = new Stack <OrderDetails>();
                        orderData.Clear();
                        foreach (var item in shoppingCart)
                        {
                            if (productFormatRepository.FindById(item.ProductFormatID).StockQuantity - item.Quantity >= 0)
                            {
                                OrderDetails orderDetails = new OrderDetails()
                                {
                                    OrderID         = orderTempID.OrderID,
                                    ProductFormatID = item.ProductFormatID,
                                    Quantity        = item.Quantity,
                                    UnitPrice       = productRepository.FindById(item.ProductID).UnitPrice
                                };
                                orderData.Push(orderDetails);
                            }
                            else
                            {
                                var productFormatTemp = productFormatRepository.FindById(item.ProductFormatID);
                                var productTemp       = productRepository.FindById(productFormatTemp.ProductID);


                                return(Json("產品:" + productTemp.ProductName + Environment.NewLine +
                                            "顏色:" + productFormatTemp.Color + Environment.NewLine +
                                            "尺寸:" + productFormatTemp.Size + Environment.NewLine +
                                            "剩餘數量:" + productFormatTemp.StockQuantity + Environment.NewLine +
                                            "請重新下訂!"));
                            }
                        }

                        foreach (var orderItem in orderData)
                        {
                            orderDetailsRepository.Create(orderItem);
                        }

                        shoppingCartRepository.DeleteByMemberId(memberID);

                        return(Json("下訂成功"));
                    }
                    else
                    {
                        return(Json("電話格式有誤"));
                    }
                }
                else
                {
                    return(Json("姓名不符合格式"));
                }
            }
        }