Exemple #1
0
        /**
         * This Method is called the first time the user Enter the view
         * @Author: Anthony Wong
         * @Version 1.0
         * @Date: November 2,2018
         * */
        public IActionResult ReportHour()
        {
            ReportHourModel Hour = new ReportHourModel
            {
                InvalidHour = false
            };

            return(View(Hour));
        }
Exemple #2
0
        public void TestHomeReportHourPara()
        {
            //Arrange
            HomeController  controller      = new HomeController();
            ReportHourModel reportHourModel = new ReportHourModel();

            reportHourModel.StoreHour   = "15";
            reportHourModel.InvalidHour = true;

            //Act
            ViewResult result = controller.ReportHour(reportHourModel) as ViewResult;

            //Assert
            Assert.NotNull(reportHourModel);
        }
Exemple #3
0
        public IActionResult ReportHour(ReportHourModel Hour)
        {
            Hour.InvalidHour          = true;
            Hour.HoursAlreadyInputted = true;

            var db = new DatabaseConnect().ConnectionString();


            //We should have more restriction but this is fine for demonstration as example for now
            bool isNumber = int.TryParse(Hour.StoreHour, out int NumOfHour);

            string email       = HttpContext.Session.GetString("_Name");
            int    empID       = 0;
            int    contractID  = 0;
            int    actualMonth = DateTime.Now.Month;
            int    actualYear  = DateTime.Now.Year;


            if ((isNumber == true) && (NumOfHour >= 0) && (NumOfHour < 300))
            {
                Hour.InvalidHour = false;

                //Do code to Database
                using (SqlConnection con = new SqlConnection(db))
                {
                    string sql1 = "SELECT ContractorID FROM Contractor WHERE Email = '" + email + "'";

                    using (SqlCommand cmd = new SqlCommand(sql1, con))
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            empID = reader.GetInt32(0);
                        }
                        reader.Close();
                        con.Close();
                    }

                    string sql2 = "SELECT ContractId FROM Contract WHERE ContractorId = " + empID + "";

                    using (SqlCommand cmd = new SqlCommand(sql2, con))
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            contractID = reader.GetInt32(0);
                        }
                        reader.Close();
                        con.Close();
                    }

                    int    lastMonth = GetPastMonth(contractID);
                    string sql3      = "INSERT EmployeeHour (ContractId, Year, Month, CurrentMonth, PreviousMonth) VALUES (" + contractID + ", " + actualYear + ", " + actualMonth + ", " + NumOfHour + ", " + lastMonth + ")";

                    using (SqlCommand cmd = new SqlCommand(sql3, con))
                    {
                        if ((contractID != 0) && (PerviouslyEntered(contractID) == false))
                        {
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                        }

                        else if (PerviouslyEntered(contractID) == true)
                        {
                            Hour.HoursAlreadyInputted = true;
                            return(View(Hour));
                        }

                        else
                        {
                            return(RedirectToAction("ErrorContract"));
                        }
                    }
                    return(RedirectToAction("Welcome"));
                }
            }
            else
            {
                return(View(Hour));
            }
        }