예제 #1
0
        public ContentResult AddAll(FormCollection form)
        {
            // add new attendance row for all employees
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            string[] keys  = new string[] { "v" };
            int      count = 0;

            if (this.HasValues(form, keys))
            {
                if (!this.CheckLogin(AccountType.Applicant) && ((Employee)this.GetAccount().Profile).Department.Type
                    == DepartmentType.HumanResources)
                {
                    try
                    {
                        DBHandler db = new DBHandler();

                        using (DataTable dt = db.Execute <DataTable>(
                                   CRUD.READ,
                                   "SELECT Profile FROM Account WHERE Type = " + ((int)AccountType.Employee) + " OR Type = "
                                   + ((int)AccountType.DepartmentHead)))
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                Employee   emp = new Employee(Int32.Parse(row["Profile"].ToString()));
                                Attendance at  = new Attendance();
                                try
                                {
                                    at = new Attendance().Find(emp.EmployeeID, DateTime.Now, recursive: false, byPrimary: false);
                                }
                                catch (Exception e)
                                {
                                    at.Absent    = 0;
                                    at.Late      = 0;
                                    at.Leave     = emp.GetNumLeaves(DateTime.Now);
                                    at.Overtime  = 0;
                                    at.Present   = 0;
                                    at.Undertime = 0;
                                    at.Date      = DateTime.Now;
                                    at.Employee  = emp;
                                    if (String.IsNullOrEmpty(form.GetValue("v").AttemptedValue))
                                    {
                                        throw new Exception("Form is incomplete");
                                    }

                                    at.TotalWorkingDays = Int32.Parse(form.GetValue("v").AttemptedValue);

                                    at.Create();
                                    count++;
                                }
                            }

                            json["message"] = "Successfully create Attendance rows for " + count + " employees";
                        }
                    } catch (Exception e)
                    {
                        json["error"]   = true;
                        json["message"] = e.Message;
                    }
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "You are not authorized to continue";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "Form is incomplete";
            }

            return(Content(json.ToString(), "application/json"));
        }
예제 #2
0
        public ContentResult AddAttendance(FormCollection form)
        {
            // add new attendance row for an employee
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            string[] keys = new string[] { "id", "v" };

            if (this.HasValues(form, keys))
            {
                if (!this.CheckLogin(AccountType.Applicant) && ((Employee)this.GetAccount().Profile).Department.Type
                    == DepartmentType.HumanResources)
                {
                    try
                    {
                        if (String.IsNullOrEmpty(form.GetValue("id").AttemptedValue))
                        {
                            throw new Exception("Form is incomplete");
                        }

                        Employee emp = new Employee(Int32.Parse(form.GetValue("id").AttemptedValue), true);

                        Attendance at = new Attendance();
                        try
                        {
                            at = new Attendance().Find(emp.EmployeeID, DateTime.Now, recursive: false, byPrimary: false);
                        }
                        catch (Exception e)
                        {
                            at.Absent    = 0;
                            at.Late      = 0;
                            at.Overtime  = 0;
                            at.Present   = 0;
                            at.Undertime = 0;
                            at.Date      = DateTime.Now;
                            at.Employee  = emp;
                            at.Leave     = emp.GetNumLeaves(DateTime.Now);

                            if (String.IsNullOrEmpty(form.GetValue("v").AttemptedValue))
                            {
                                throw new Exception("Form is incomplete");
                            }

                            at.TotalWorkingDays = Int32.Parse(form.GetValue("v").AttemptedValue);

                            at.Create();

                            json["message"] = "Successfully created Attendance row for: <b>" +
                                              emp.Profile.FirstName + " " + emp.Profile.LastName + "</b>";
                        }
                    }
                    catch (Exception e)
                    {
                        json["error"]   = true;
                        json["message"] = e.Message;
                    }
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "You are not authorized to continue";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "Form is incomplete";
            }

            return(Content(json.ToString(), "application/json"));
        }