Пример #1
0
        /// <summary>
        /// Updates the employee loan.
        /// </summary>
        /// <param name="employeeLoanView">The employee loan view.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// employeeLoanView
        /// or
        /// employeeLoanData
        /// </exception>
        public string UpdateEmployeeLoan(IEmployeeLoanView employeeLoanView)
        {
            if (employeeLoanView == null)
            {
                throw new ArgumentNullException(nameof(employeeLoanView));
            }

            var result = string.Empty;


            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    var employeeLoanData =
                        dbContext.EmployeeLoans.SingleOrDefault(m => m.EmployeeLoanId.Equals(employeeLoanView.EmployeeLoanId));
                    if (employeeLoanData == null)
                    {
                        throw new ArgumentNullException(nameof(employeeLoanData));
                    }

                    if (employeeLoanData != null)
                    {
                        employeeLoanData.IsApproved   = employeeLoanView.IsApproved;
                        employeeLoanData.Tenure       = employeeLoanView.Tenure;
                        employeeLoanData.Reason       = employeeLoanView.Reason;
                        employeeLoanData.DateDisburst = employeeLoanView.DisburstDate;
                        employeeLoanData.HRComment    = employeeLoanView.HRComment;
                        employeeLoanData.AgreedDate   = employeeLoanView.AgreedDate;
                        employeeLoanData.ExpectedDate = employeeLoanView.ExpectedDate;
                        employeeLoanData.Amount       = employeeLoanView.LoanAmount;
                        employeeLoanData.InterestRate = employeeLoanView.InterestRate;



                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                result = string.Format("Update Employee Loan Information - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Saves the employee loan information.
        /// </summary>
        /// <param name="employeeLoan">The employee loan.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">employeeLoan</exception>
        public string SaveEmployeeLoanInfo(IEmployeeLoanView employeeLoan)
        {
            if (employeeLoan == null)
            {
                throw new ArgumentNullException(nameof(employeeLoan));
            }

            string result = string.Empty;

            var newReocord = new EmployeeLoan
            {
                EmployeeId   = employeeLoan.EmployeeId,
                CompanyId    = employeeLoan.CompanyId,
                Tenure       = employeeLoan.Tenure,
                LoanTypeId   = employeeLoan.LoanId,
                Reason       = employeeLoan.Reason,
                DateCreated  = DateTime.UtcNow,
                IsActive     = true,
                AgreedDate   = null,
                Amount       = employeeLoan.LoanAmount,
                IsApproved   = null,
                HRComment    = null,
                DateDisburst = employeeLoan.DisburstDate,
                ExpectedDate = employeeLoan.ExpectedDate,
                PeriodRemain = employeeLoan.Tenure,
            };

            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    dbContext.EmployeeLoans.Add(newReocord);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("Save Employee loan info - {0}, {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Deletes the employee loan.
        /// </summary>
        /// <param name="employeeLoanView">The employee loan view.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// employeeLoanView
        /// or
        /// employeeLoanData
        /// </exception>
        public string DeleteEmployeeLoan(IEmployeeLoanView employeeLoanView)
        {
            if (employeeLoanView == null)
            {
                throw new ArgumentNullException(nameof(employeeLoanView));
            }

            var result = string.Empty;


            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    var employeeLoanData =
                        dbContext.EmployeeLoans.SingleOrDefault(m => m.EmployeeLoanId.Equals(employeeLoanView.EmployeeLoanId));
                    if (employeeLoanData == null)
                    {
                        throw new ArgumentNullException(nameof(employeeLoanData));
                    }

                    if (employeeLoanData != null)
                    {
                        employeeLoanData.IsActive   = false;
                        employeeLoanData.IsApproved = false;
                        //Sets IsActive to false
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                result = string.Format("Delete Employee Loan Information - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }
            return(result);
        }