private void Reload( )
        {
            string   rowConstraints = "";
            MainPage mainPage       = baseControl as MainPage;

            if (mainPage.UserRole == "USER")
            {
                rowConstraints        = "EmployeeID = " + mainPage.EmployeeID;
                btn_accept.Visibility = btn_reject.Visibility = Visibility.Collapsed;
            }
            data = LeaveApplications.FetchApplications(rowConstraints);
            if (data.Rows.Count == 0)
            {
                lb_message.Visibility = Visibility.Visible;
                subGrid.Visibility    = Visibility.Collapsed;
            }
            else
            {
                lb_message.Visibility = Visibility.Collapsed;
                subGrid.Visibility    = Visibility.Visible;
                tb_employeeID.Text    = data.Rows[index][0].ToString( );
                tb_employeeName.Text  = Employees.GetSpecificEmployeeInfo("EmployeeName", "EmployeeID = " + tb_employeeID.Text).Rows[0][0].ToString( );
                tb_leaveType.Text     = data.Rows[index][1].ToString( );
                tb_leavingDate.Text   = data.Rows[index][2].ToString( );
                tb_joiningDate.Text   = data.Rows[index][3].ToString( );
                tb_description.Text   = data.Rows[index][4].ToString( );
            }
        }
Example #2
0
        ///<summary>
        ///This method is tagged save leave application button click event; enables and reset leave application form inputs for data entry
        ///</summary>
        /// <returns></returns>
        ///
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (ValidateLeaveApplicationFormInputs())
            {
                var application = new LeaveApplications
                {
                    EmpId = txtEmpId.Text.Trim(),
                    ReplacementStaffId = txtReplacementEmpId.Text.Trim(),
                    SupervisorStaffId  = txtSupervisorEmpId.Text.Trim(),
                    LeaveType          = cmbLeaveType.Text,
                    LeaveDays          = Convert.ToInt32(txtLeaveDays.Text),
                    FromDate           = dtpFromDate.Value,
                    ToDate             = dtpToDate.Value,
                    ReturnDate         = dtpReturnDate.Value,
                    Details            = rtbDetails.Text.Trim().ToUpper(),
                    IsApproved         = chkBxIsApproved.Checked
                };

                if (_addOrEditApplication == 'A')
                {
                    SaveLeaveApplication(application);
                }
                else
                {
                    UpdateLeaveApplication(application);
                }

                txtReplacementEmpId.Enabled = false;
                txtReplacementEmpName.Text  = string.Empty;
                txtSupervisorEmpId.Enabled  = false;
                txtSupervisorName.Text      = string.Empty;
                cmbLeaveType.Enabled        = false;
                cmbLeaveType.Text           = string.Empty;
                txtLeaveDays.Enabled        = false;
                txtLeaveDays.Text           = string.Empty;
                dtpFromDate.Enabled         = false;
                dtpFromDate.Value           = DateTime.Now;
                dtpToDate.Enabled           = false;
                dtpToDate.Value             = DateTime.Now;
                dtpReturnDate.Enabled       = false;
                dtpReturnDate.Value         = DateTime.Now;
                chkBxIsApproved.Checked     = false;
                chkBxIsApproved.Enabled     = false;
                rtbDetails.Text             = string.Empty;
                rtbDetails.Enabled          = false;

                btnSave.Enabled   = false;
                btnCancel.Enabled = false;
                btnAdd.Enabled    = true;
            }
        }
        public async Task <LeaveApplications> ApproveLeaveApplication(LeaveApplication model)
        {
            LeaveApplications _obj = new LeaveApplications();

            using (SqlConnection con = SqlCon())
            {
                SqlCommand cmd = SqlCmd(con);
                cmd.CommandText = "ApproveLeaveApplication";
                cmd.Parameters.AddWithValue("@approverUserName", model.approverUserName);
                cmd.Parameters.AddWithValue("@trackingRef", model.trackingRef);
                cmd.Parameters.AddWithValue("@approverDescription", model.approverDescription);
                cmd.Parameters.AddWithValue("@approverCommand", model.approverCommand);

                SqlParameter prm1 = new SqlParameter
                {
                    ParameterName = "@status",
                    SqlDbType     = SqlDbType.NVarChar,
                    Size          = 50,
                    Direction     = ParameterDirection.Output
                };
                cmd.Parameters.Add(prm1);

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                try
                {
                    con.Open();
                    da.Fill(dt);
                    _obj.status = (string)prm1.Value;
                }
                catch (SqlException ex)
                {
                    _obj.status  = ex.Number.ToString();
                    _obj.message = ex.Message;
                }
                finally
                {
                    dt.Dispose();
                    da.Dispose();
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                    }
                    cmd.Dispose();
                }
            }

            return(_obj);
        }
        public int DeleteLeaveApplication(LeaveApplications application)
        {
            _context.LeaveApplications.Remove(application);

            try
            {
                return(_context.SaveChanges());
            }
            catch (Exception ex)
            {
                Clf.CreateErrorLog(ErrorLogPath, "DB Transaction Error DeleteLeaveApplication Method: " + ex.Message + ": " + ex.InnerException);
            }

            return(0);
        }
        public async Task <ActionResult> VerifyAsync(Verification model)
        {
            var meta = await AppUsers.GetCurrentAsync().ConfigureAwait(true);

            try
            {
                await LeaveApplications.VerifyAsync(this.Tenant, meta.LoginId, meta.UserId, model).ConfigureAwait(true);

                return(this.Ok());
            }
            catch (Exception ex)
            {
                return(this.Failed(ex.Message, HttpStatusCode.InternalServerError));
            }
        }
        public async Task <LeaveApplications> DisableLeaveApplication(LeaveApplication model)
        {
            LeaveApplications _obj = new LeaveApplications();

            using (SqlConnection con = SqlCon())
            {
                SqlCommand cmd = SqlCmd(con);
                cmd.CommandText = "DisableLeaveApplication";
                cmd.Parameters.AddWithValue("@trackingRef", model.trackingRef);

                SqlParameter prm1 = new SqlParameter
                {
                    ParameterName = "@status",
                    SqlDbType     = SqlDbType.NVarChar,
                    Size          = 50,
                    Direction     = ParameterDirection.Output
                };
                cmd.Parameters.Add(prm1);
                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    _obj.status = (string)prm1.Value;
                }
                catch (SqlException ex)
                {
                    _obj.status  = ex.Number.ToString();
                    _obj.message = ex.Message;
                }
                finally
                {
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                    }
                    cmd.Dispose();
                }
            }

            return(_obj);
        }
Example #7
0
        ///<summary>
        ///This method makes an api request to update an employee's leave application in the database
        ///</summary>
        /// <returns></returns>
        ///
        private void UpdateLeaveApplication(LeaveApplications application)
        {
            string apiUrl = "http://localhost/AbcHrApi/api/leave/UpdateApplication";

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var response = client.PutAsync(apiUrl, new StringContent(JsonConvert.SerializeObject(application), Encoding.UTF8, "application/json"));

                    using (var updatedApplicationResponseContent = response.Result.Content)
                    {
                        var updatedApplicationResult   = updatedApplicationResponseContent.ReadAsStringAsync();
                        var updatedApplicationResponse = JsonConvert.DeserializeObject <RequestResponse>(updatedApplicationResult.Result);

                        if (updatedApplicationResponse.Status == "Success")
                        {
                            dgvLeaveApplications.DataSource = GetEmployeeLeaveApplications(txtEmpId.Text);
                            dgvLeaveApplications.Refresh();
                            lblSystemMessage.ForeColor = Color.Blue;
                            lblSystemMessage.Text      = updatedApplicationResponse.Remarks;
                        }
                        else
                        {
                            lblSystemMessage.ForeColor = Color.Red;
                            lblSystemMessage.Text      = updatedApplicationResponse + ", kindly contact system administrator";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Clf.CreateErrorLog(ErrorLogPath, "Error at UpdateLeaveApplication Method: " + ex.Message + ": " + ex.InnerException);
                    lblSystemMessage.ForeColor = Color.Red;
                    lblSystemMessage.Text      = @"An error has occured, kindly contact system administrator";
                }
            }
        }
Example #8
0
        public ActionResult <RequestResponse> PostLeaveApplication(LeaveApplications application)
        {
            var currentDate = DateTime.Now;

            application.CreatedOn  = currentDate;
            application.ModifiedOn = currentDate;

            var result = _leaveApplicationsRepository.SaveLeaveApplication(application);

            if (result > 0)
            {
                if (!application.IsApproved)
                {
                    //semd email notification for application to be approved
                    var applicant = _employeeRepository.FindEmployeeById(application.EmpId);

                    var supervisor = _employeeRepository.FindEmployeeById(application.SupervisorStaffId);

                    TextInfo myTI = new CultureInfo("en-US", false).TextInfo;

                    var message = @"Dear " + myTI.ToTitleCase(supervisor.FirstName.ToLower()) + ", \n\n" + myTI.ToTitleCase(applicant.FirstName.ToLower()) + " " + myTI.ToTitleCase(applicant.LastName.ToLower()) + " has applied for " + application.LeaveType.ToLower() + " leave for " + application.LeaveDays + " day(s), starting from " + application.FromDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + " to " + application.ToDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + ", with a return date of " + application.ReturnDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + "."
                                  + "\n\nKindly approve or reject the application by responding to this email to notify the HR Department. \n\nThanks,\nHuman Resource Department";

                    //Emu.SendEmail(supervisor.EmailId, "Leave Application", message, "*****@*****.**", applicant.EmailId);
                    Emu.SendEmail(supervisor.EmailId, "Leave Application", message);
                }

                return(new RequestResponse
                {
                    Status = "Success",
                    Remarks = "Leave application added successfully"
                });
            }

            return(new RequestResponse
            {
                Status = "Failure",
                Remarks = "Add new record failed"
            });
        }
Example #9
0
        public ActionResult <RequestResponse> PutLeaveApplication(LeaveApplications application)
        {
            application.ModifiedOn = DateTime.Now;

            var result = _leaveApplicationsRepository.EditLeaveApplication(application);

            if (result > 0)
            {
                if (application.IsApproved)
                {
                    //semd email notification for application to be approved
                    var applicant = _employeeRepository.FindEmployeeById(application.EmpId);

                    var supervisor = _employeeRepository.FindEmployeeById(application.SupervisorStaffId);

                    TextInfo myTI = new CultureInfo("en-US", false).TextInfo;

                    var message = @"Dear " + myTI.ToTitleCase(applicant.FirstName.ToLower()) + " " + myTI.ToTitleCase(applicant.LastName.ToLower()) + " your application for " + application.LeaveType.ToLower() + " leave for " + application.LeaveDays + " day(s), starting from " + application.FromDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + " to " + application.ToDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + ", with a return date of "
                                  + application.ReturnDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + ", has been approved." + "\n\n Best Regards,\nHuman Resource Department.";

                    //Emu.SendEmail(applicant.EmailId, "Leave Application", message, "*****@*****.**", supervisor.EmailId);
                    Emu.SendEmail(applicant.EmailId, "Leave Application", message);
                }


                return(new RequestResponse
                {
                    Status = "Success",
                    Remarks = "Leave application has been updated successfully"
                });
            }

            return(new RequestResponse
            {
                Status = "Failure",
                Remarks = "Update action failed"
            });
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (sender == btn_next)
     {
         index = index + 1 >= data.Rows.Count ? 0 : index + 1;
     }
     else if (sender == btn_prev)
     {
         index = index <= 0 ? data.Rows.Count - 1 : index - 1;
     }
     else if (sender == btn_reject)
     {
         string rowConstraints = "EmployeeID = " + tb_employeeID.Text + " AND LeaveType = '" + tb_leaveType.Text.Replace("'", "''") + "' AND LeavingDate = '" + tb_leavingDate.Text + "' AND JoiningDate = '" + tb_joiningDate.Text + "' AND LeaveDescription = '" + tb_description.Text.Replace("'", "''") + "'";
         LeaveApplications.RejectApplications(rowConstraints);
         if (index + 1 == data.Rows.Count)
         {
             index--;
         }
     }
     else
     {
         MainPage            mainPage            = baseControl as MainPage;
         LeaveAssignmentPage leaveAssignmentPage = mainPage.LeaveAssignmentPage;
         mainPage.JobStack.Push(this);
         mainPage.Container.Navigate(leaveAssignmentPage);
         leaveAssignmentPage.icb_employees.Text  = tb_employeeName.Text;
         leaveAssignmentPage.icb_employeeID.Text = tb_employeeID.Text;
         leaveAssignmentPage.icb_leaveTypes.Text = tb_leaveType.Text;
         leaveAssignmentPage.dp_leavingDate.Text = tb_leavingDate.Text;
         leaveAssignmentPage.dp_joiningDate.Text = tb_joiningDate.Text;
         //	(baseControl as MainPage).LeaveAssignmentPage.AssignLeave( tb_employeeID.Text, tb_leaveType.Text, new DateString( tb_leavingDate.Text ).ToDateTime( ), new DateString( tb_joiningDate.Text ).ToDateTime( ));
         index = 0;
         return;
     }
     Reload( );
 }
Example #11
0
 public IEnumerable <LeaveApplication> Create(IEnumerable <LeaveApplication> items)
 {
     return(LeaveApplications.Create(items));
 }
Example #12
0
 public LeaveApplication Update(LeaveApplication item)
 {
     return(LeaveApplications.Update(item));
 }
Example #13
0
 public LeaveApplication Create(LeaveApplication item)
 {
     return(LeaveApplications.Create(item));
 }
Example #14
0
        // Note: Due to the immutability of endpoints, If you want to use filtering etc you will need to make requests via the endpoints themselves, not using the sugar methods below

        public async Task <IEnumerable <LeaveApplication> > CreateAsync(IEnumerable <LeaveApplication> items)
        {
            return(await LeaveApplications.CreateAsync(items));
        }
Example #15
0
 public async Task <LeaveApplication> UpdateAsync(LeaveApplication item)
 {
     return(await LeaveApplications.UpdateAsync(item));
 }
Example #16
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (icb_leaveType.Text.Length == 0 || dp_leavingDate.SelectedDate == null || dp_joiningDate.SelectedDate == null)
            {
                MessageBox.Show("Please fill in the required details.", "Incomplete", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (lb_message.Visibility == System.Windows.Visibility.Visible)
            {
                MessageBox.Show(lb_message.Content + "!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DateTime appliedLeavingDate = dp_leavingDate.SelectedDate.Value;
            DateTime appliedJoiningDate = dp_joiningDate.SelectedDate.Value;

            if (appliedLeavingDate < DateTime.Today)
            {
                MessageBox.Show("Leaving date cannot be a past date.", "Date Past", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            MainPage   mainPage           = baseControl as MainPage;
            string     columns            = "LeavingDate, JoiningDate";
            string     rowConstraints     = "EmployeeID = " + mainPage.EmployeeID;
            DataTable  data               = LeaveList.GetSpecificLeaveInfo(columns, rowConstraints);
            string     clashInfo          = "";
            DateString currentLeavingDate = new DateString( );
            DateString currentJoiningDate = new DateString( );

            foreach (DataRow row in data.Rows)
            {
                currentLeavingDate = row[0].ToString( );
                currentJoiningDate = row[1].ToString( );

                if (appliedLeavingDate >= currentLeavingDate && appliedLeavingDate <= currentJoiningDate ||
                    appliedJoiningDate >= currentLeavingDate && appliedJoiningDate <= currentJoiningDate ||
                    appliedLeavingDate < currentLeavingDate && appliedJoiningDate > currentJoiningDate)
                {
                    clashInfo = "You are already assigned a leaving date of " + currentLeavingDate + " and a joining date of " + currentJoiningDate;
                    break;
                }
            }
            if (clashInfo.Length > 0)
            {
                MessageBox.Show(clashInfo);
                return;
            }
            mainPage.LeaveAssignmentPage.Load( );
            mainPage.LeaveAssignmentPage.icb_employeeID.Text         = mainPage.EmployeeID;
            mainPage.LeaveAssignmentPage.icb_leaveTypes.Text         = icb_leaveType.Text;
            mainPage.LeaveAssignmentPage.dp_leavingDate.SelectedDate = dp_leavingDate.SelectedDate;
            mainPage.LeaveAssignmentPage.dp_joiningDate.SelectedDate = dp_joiningDate.SelectedDate;
            object balance = mainPage.LeaveAssignmentPage.lb_balance.Content;

            if (balance.ToString( ).Length == 0 || balance.ToString( ) == "!!" || double.Parse(balance.ToString( )) < 0)
            {
                if (MessageBox.Show("Application might not be granted due to balance issues.\nDo you still wish to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                    return;
                }
            }
            LeaveApplications.SendApplication(mainPage.EmployeeID, icb_leaveType.Text.Replace("'", "''"), dp_leavingDate.SelectedDate.Value, dp_joiningDate.SelectedDate.Value, tb_description.Text.Replace("'", "''"));
            MessageBox.Show("Application sent!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Example #17
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MainPage     mainPage = baseControl as MainPage;
            Stack <Page> jobStack = mainPage.JobStack;

            if (icb_employeeID.Text.Length == 0 || icb_leaveTypes.Text.Length == 0 || dp_leavingDate.SelectedDate == null || dp_joiningDate.SelectedDate == null)
            {
                MessageBox.Show("Please fill in the required fields.", "Incomplete", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }
            if (lb_message.Visibility == System.Windows.Visibility.Visible)
            {
                MessageBox.Show(lb_message.Content.ToString( ) + "!", "Invalid Interval", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (dp_leavingDate.SelectedDate.Value < DateTime.Today)
            {
                MessageBox.Show("Leaving date cannot be a past date.", "Date Past", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DataTable data               = LeavePeriods.GetLeavePeriods( );
            string    startingDate       = "";
            string    endingDate         = "";
            bool      leavingDateIsValid = false;
            bool      joiningDateIsValid = false;

            foreach (DataRow row in data.Rows)
            {
                if (dp_leavingDate.SelectedDate.Value >= new DateString(row[0]))
                {
                    startingDate       = row[0].ToString( );
                    leavingDateIsValid = true;
                    break;
                }
            }
            foreach (DataRow row in data.Rows)
            {
                if (dp_joiningDate.SelectedDate.Value.AddDays(-1) <= new DateString(row[1]))
                {
                    endingDate         = row[1].ToString( );
                    joiningDateIsValid = true;
                    break;
                }
            }
            if (!leavingDateIsValid || !joiningDateIsValid)
            {
                MessageBox.Show("The leave period is not valid. Please enter a valid one or reconfigure.", "Invalid Leave Period", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (lb_balance.Content.ToString( ) == "!!")
            {
                MessageBox.Show("The interval you entered exceeds the bounds!", "Too Big Interval", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (lb_balance.Content.ToString( ).Length == 0)
            {
                if (MessageBox.Show("No balance available. Do you wish to entitle?", "No Balance", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                {
                    EntitlementsAdder entitlementsAdder = mainPage.EntitlementsAdder;
                    jobStack.Push(this);
                    mainPage.Container.Navigate(entitlementsAdder);
                    entitlementsAdder.icb_employees.Text  = icb_employees.Text;
                    entitlementsAdder.icb_employeeID.Text = icb_employeeID.Text;
                    entitlementsAdder.icb_leaveTypes.Text = icb_leaveTypes.Text;
                    entitlementsAdder.icb_validFrom.Text  = startingDate;
                    entitlementsAdder.icb_validTo.Text    = endingDate;
                }
                else
                {
                    MessageBox.Show("Leave Not Assigned!", "Failure", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                return;
            }
            if (double.Parse(lb_balance.Content.ToString( )) < 0)
            {
                MessageBoxResult result = MessageBox.Show("Balance is insufficient! Do you wish to update entitlement?", "Insufficient Balance", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);
                if (result != MessageBoxResult.No)
                {
                    if (result == MessageBoxResult.Yes)
                    {
                        EntitlementsViewer entitlementsViewer = mainPage.EntitlementsViewer;
                        mainPage.JobStack.Push(this);
                        mainPage.Container.Navigate(entitlementsViewer);
                        entitlementsViewer.icb_employeeID.Text = icb_employeeID.Text;
                        entitlementsViewer.icb_employees.Text  = icb_employees.Text;
                        entitlementsViewer.icb_leaveTypes.Text = icb_leaveTypes.Text;
                        entitlementsViewer.icb_validFrom.Text  = startingDate;
                        entitlementsViewer.icb_validTo.Text    = endingDate;
                    }
                    return;
                }
            }
            string        values          = icb_employeeID.Text + ", '" + icb_leaveTypes.Text + "', '" + new DateString(dp_leavingDate.SelectedDate.Value) + "', '" + new DateString(dp_joiningDate.SelectedDate.Value) + "', " + lostBalance + ", '" + tb_commentBox.Text.Replace("'", "''") + "'";
            string        changes         = "Balance = " + lb_balance.Content;
            StringBuilder rowConstraints  = new StringBuilder("EmployeeID = " + icb_employeeID.Text + " AND LeaveType = '" + icb_leaveTypes.Text + "'");
            StringBuilder dateConstraints = new StringBuilder( );

            try     {
                Entitlements.UpdateEntitlementInfo(changes, rowConstraints.ToString( ));
                LeaveList.AssignLeave(values);
                data = LeaveApplications.FetchDetails("LeavingDate, JoiningDate", rowConstraints.ToString( ));
                foreach (DataRow row in data.Rows)
                {
                    if (new DateString(row[0].ToString( )) >= dp_leavingDate.SelectedDate && new DateString(row[1].ToString( )) <= dp_joiningDate.SelectedDate)
                    {
                        dateConstraints.Append("LeavingDate = '" + row[0] + "' AND JoiningDate = '" + row[1] + "' OR ");
                    }
                }
                dateConstraints.Append("1 = 2");
                rowConstraints.Append(" AND (" + dateConstraints.ToString( ) + ")");
                LeaveApplications.RejectApplications(rowConstraints.ToString( ));
                MessageBox.Show("Leave Assigned Successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }       catch (System.Data.SqlClient.SqlException exception)     {
                MessageBox.Show(exception.Message);
            }
            if (jobStack.Count > 0)
            {
                mainPage.Container.Navigate(jobStack.Pop( ));
            }
        }
Example #18
0
 public Task <LeaveApplication> CreateAsync(LeaveApplication item)
 {
     return(LeaveApplications.CreateAsync(item));
 }
        public async Task <LeaveApplications> GetFullLeaveAppplication(long pageSize, long requestPage, SearchCondition filters, string getAllOrNot)
        {
            long                    _pageSize    = pageSize;
            long                    _requestPage = requestPage;
            string                  _getAllOrNot = getAllOrNot;
            string                  _condition   = Utility.CompleteConditionString(filters);
            string                  condition    = String.IsNullOrEmpty(_condition) ? "1 = 1" : "(" + _condition + ")";
            LeaveApplications       _obj         = new LeaveApplications();
            List <LeaveApplication> list         = new List <LeaveApplication>();

            using (SqlConnection con = SqlCon())
            {
                SqlCommand cmd = SqlCmd(con);
                cmd.CommandText = "GetFullApplicationList";
                cmd.Parameters.AddWithValue("@pageSize", _pageSize);
                cmd.Parameters.AddWithValue("@requestPage", _requestPage);
                cmd.Parameters.AddWithValue("@condition", condition);
                cmd.Parameters.AddWithValue("@getAll", _getAllOrNot);

                SqlParameter prm1 = new SqlParameter
                {
                    ParameterName = "@collectionSize",
                    SqlDbType     = SqlDbType.BigInt,
                    Direction     = ParameterDirection.Output
                };
                cmd.Parameters.Add(prm1);

                SqlParameter prm2 = new SqlParameter
                {
                    ParameterName = "@activePage",
                    SqlDbType     = SqlDbType.BigInt,
                    Direction     = ParameterDirection.Output
                };
                cmd.Parameters.Add(prm2);

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                try
                {
                    con.Open();
                    da.Fill(dt);

                    _obj.collectionSize = (Int64)prm1.Value;
                    _obj.pageSize       = _pageSize;
                    _obj.activePage     = (Int64)prm2.Value;
                    _obj.status         = "000";
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            LeaveApplication app = new LeaveApplication();
                            app.trackingRef           = (string)dr[nameof(app.trackingRef)];
                            app.createdAt             = (string)dr[nameof(app.createdAt)];
                            app.applicantUserName     = (string)dr[nameof(app.applicantUserName)];
                            app.applicantDeptCode     = (string)dr[nameof(app.applicantDeptCode)];
                            app.applicantTitleCode    = (string)dr[nameof(app.applicantTitleCode)];
                            app.fromTime              = (dr[nameof(app.fromTime)] as string) ?? String.Empty;
                            app.toTime                = (dr[nameof(app.toTime)] as string) ?? String.Empty;
                            app.timeConsumed          = (dr[nameof(app.timeConsumed)] as int?) ?? 0;
                            app.applicantDescription  = (dr[nameof(app.applicantDescription)] as string) ?? String.Empty;
                            app.leaveCode             = (dr[nameof(app.leaveCode)] as string) ?? String.Empty;
                            app.isValid               = (bool)dr[nameof(app.isValid)];
                            app.progress              = (string)dr[nameof(app.progress)];
                            app.approverUserName      = (dr[nameof(app.approverUserName)] as string) ?? String.Empty;
                            app.approverDescription   = (dr[nameof(app.approverDescription)] as string) ?? String.Empty;
                            app.createdByAdmin        = (bool)dr[nameof(app.createdByAdmin)];
                            app.approverUserName      = (dr[nameof(app.approverUserName)] as string) ?? String.Empty;
                            app.finalStatus           = (bool)dr[nameof(app.finalStatus)];
                            app.applicantUserFullName = (string)dr[nameof(app.applicantUserFullName)];
                            app.approverUserFullName  = (dr[nameof(app.approverUserFullName)] as string) ?? String.Empty;
                            app.approverCommand       = (dr[nameof(app.approverCommand)] as string) ?? String.Empty;
                            list.Add(app);
                        }
                        _obj.apps = list;
                    }
                }
                catch (SqlException ex)
                {
                    _obj.status  = ex.Number.ToString();
                    _obj.message = ex.Message;
                }
                finally
                {
                    dt.Dispose();
                    da.Dispose();
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                    }
                    cmd.Dispose();
                }
            }
            return(_obj);
        }
Example #20
0
 public Task <IEnumerable <LeaveApplication> > UpdateAsync(IEnumerable <LeaveApplication> items)
 {
     return(LeaveApplications.UpdateAsync(items));
 }
        public async Task <LeaveApplications> PendingLeaveApplication(string userName)
        {
            LeaveApplications       _obj = new LeaveApplications();
            List <LeaveApplication> list = new List <LeaveApplication>();

            using (SqlConnection con = SqlCon())
            {
                SqlCommand cmd = SqlCmd(con);
                cmd.CommandText = "GetPendingApplication";
                cmd.Parameters.AddWithValue("@userName", userName);


                SqlParameter prm1 = new SqlParameter
                {
                    ParameterName = "@status",
                    SqlDbType     = SqlDbType.NVarChar,
                    Size          = 50,
                    Direction     = ParameterDirection.Output
                };
                cmd.Parameters.Add(prm1);

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                try
                {
                    con.Open();
                    da.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            LeaveApplication app = new LeaveApplication();
                            app.trackingRef           = (string)dr[nameof(app.trackingRef)];
                            app.createdAt             = (string)dr[nameof(app.createdAt)];
                            app.applicantUserName     = (string)dr[nameof(app.applicantUserName)];
                            app.applicantDeptCode     = (string)dr[nameof(app.applicantDeptCode)];
                            app.applicantTitleCode    = (string)dr[nameof(app.applicantTitleCode)];
                            app.fromTime              = (dr[nameof(app.fromTime)] as string) ?? String.Empty;
                            app.toTime                = (dr[nameof(app.toTime)] as string) ?? String.Empty;
                            app.timeConsumed          = (dr[nameof(app.timeConsumed)] as int?) ?? 0;
                            app.applicantDescription  = (dr[nameof(app.applicantDescription)] as string) ?? String.Empty;
                            app.leaveCode             = (dr[nameof(app.leaveCode)] as string) ?? String.Empty;
                            app.isValid               = (bool)dr[nameof(app.isValid)];
                            app.progress              = (string)dr[nameof(app.progress)];
                            app.approverUserName      = (dr[nameof(app.approverUserName)] as string) ?? String.Empty;
                            app.approverDescription   = (dr[nameof(app.approverDescription)] as string) ?? String.Empty;
                            app.createdByAdmin        = (bool)dr[nameof(app.createdByAdmin)];
                            app.approverUserName      = (dr[nameof(app.approverUserName)] as string) ?? String.Empty;
                            app.finalStatus           = (bool)dr[nameof(app.finalStatus)];
                            app.applicantUserFullName = (string)dr[nameof(app.applicantUserFullName)];

                            list.Add(app);
                        }
                        _obj.apps = list;
                    }
                    _obj.status = (string)prm1.Value;
                }
                catch (SqlException ex)
                {
                    _obj.status  = ex.Number.ToString();
                    _obj.message = ex.Message;
                }
                finally
                {
                    dt.Dispose();
                    da.Dispose();
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                    }
                    cmd.Dispose();
                }
            }

            return(_obj);
        }