public IActionResult Add([FromBody] dynamic employeeData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (employeeData != null)
                {
                    Lms_EmployeePoco employeePoco = JsonConvert.DeserializeObject <Lms_EmployeePoco>(JsonConvert.SerializeObject(employeeData[0]));

                    if (employeePoco.Id < 1 && employeePoco.FirstName.Trim() != string.Empty)
                    {
                        employeePoco.CreatedBy = sessionData.UserId;
                        var employeeId = _employeeLogic.CreateNewEmployee(employeePoco, (int)sessionData.BranchId);
                        if (!string.IsNullOrEmpty(employeeId))
                        {
                            var jObject        = JObject.Parse(employeeId);
                            var returnedObject = (string)jObject.SelectToken("ReturnedValue");
                            result = (string)JObject.Parse(returnedObject).SelectToken("EmployeeId");
                            if (result.Length > 0)
                            {
                                result = Convert.ToInt32(result) < 1 ? "" : result;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }
        public IActionResult Add([FromBody] dynamic employeeData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (employeeData != null)
                {
                    Lms_EmployeePoco employeePoco = JsonConvert.DeserializeObject <Lms_EmployeePoco>(JsonConvert.SerializeObject(employeeData[0]));

                    if (employeePoco.Id < 1 && employeePoco.FirstName.Trim() != string.Empty)
                    {
                        _configurationLogic  = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext));
                        _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext));

                        var parentGLForEmployeeAccount = _configurationLogic.GetSingleById(1).ParentGLForEmployeeAccount;
                        var accounts      = _chartOfAccountLogic.GetList().Where(c => c.ParentGLCode == parentGLForEmployeeAccount).ToList();
                        var newAccountId  = accounts.Max(c => c.Id) + 1;
                        var newEmployeeId = _employeeLogic.GetMaxId() + 1;

                        using (var scope = new TransactionScope())
                        {
                            Lms_ChartOfAccountPoco accountPoco = new Lms_ChartOfAccountPoco();
                            accountPoco.Id             = newAccountId;
                            accountPoco.ParentGLCode   = parentGLForEmployeeAccount;
                            accountPoco.AccountName    = employeePoco.FirstName + employeePoco.LastName;
                            accountPoco.BranchId       = sessionData.BranchId == null ? 1 : (int)sessionData.BranchId;
                            accountPoco.CurrentBalance = 0;
                            accountPoco.IsActive       = true;
                            accountPoco.Remarks        = "Employee Account Payable";
                            accountPoco.CreateDate     = DateTime.Now;
                            accountPoco.CreatedBy      = sessionData.UserId;

                            var addedAcc = _chartOfAccountLogic.Add(accountPoco);
                            if (addedAcc.Id > 0)
                            {
                                employeePoco.Id         = newEmployeeId;
                                employeePoco.AccountId  = addedAcc.Id;
                                employeePoco.CreateDate = DateTime.Now;
                                employeePoco.CreatedBy  = sessionData.UserId;
                                var employeeId = _employeeLogic.Add(employeePoco).Id;

                                if (employeeId > 0)
                                {
                                    scope.Complete();
                                    result = employeeId.ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }
        public IActionResult Update([FromBody] dynamic employeeData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (employeeData != null)
                {
                    Lms_EmployeePoco employeePoco = JsonConvert.DeserializeObject <Lms_EmployeePoco>(JsonConvert.SerializeObject(employeeData[0]));

                    if (employeePoco.Id > 0 && employeePoco.FirstName.Trim() != string.Empty)
                    {
                        var employee = _employeeLogic.GetSingleById(employeePoco.Id);
                        // it is required to pull existing data first,
                        // cause there are some data which do not come from UI

                        employee.FirstName         = employeePoco.FirstName;
                        employee.LastName          = employeePoco.LastName;
                        employee.DriverLicenseNo   = employeePoco.DriverLicenseNo;
                        employee.SocialInsuranceNo = employeePoco.SocialInsuranceNo;
                        employee.EmployeeTypeId    = employeePoco.EmployeeTypeId;
                        employee.IsHourlyPaid      = employeePoco.IsHourlyPaid;
                        employee.HourlyRate        = employeePoco.HourlyRate;

                        employee.IsSalaried           = employeePoco.IsSalaried;
                        employee.SalaryAmount         = employeePoco.SalaryAmount;
                        employee.IsCommissionProvided = employeePoco.IsCommissionProvided;
                        employee.CommissionPercentage = employeePoco.CommissionPercentage;
                        employee.IsFuelChargeProvided = employeePoco.IsFuelChargeProvided;
                        employee.FuelPercentage       = employeePoco.FuelPercentage;
                        employee.RadioInsuranceAmount = employeePoco.RadioInsuranceAmount;
                        employee.InsuranceAmount      = employeePoco.InsuranceAmount;
                        employee.SalaryTerm           = employeePoco.SalaryTerm;
                        employee.IsActive             = employeePoco.IsActive;

                        employee.UnitNumber   = employeePoco.UnitNumber;
                        employee.AddressLine  = employeePoco.AddressLine;
                        employee.CityId       = employeePoco.CityId;
                        employee.ProvinceId   = employeePoco.ProvinceId;
                        employee.CountryId    = employeePoco.CountryId;
                        employee.PostCode     = employeePoco.PostCode;
                        employee.EmailAddress = employeePoco.EmailAddress;
                        employee.MobileNumber = employeePoco.MobileNumber;
                        employee.FaxNumber    = employeePoco.FaxNumber;
                        employee.PhoneNumber  = employeePoco.PhoneNumber;


                        var poco = _employeeLogic.Update(employee);
                        result = poco.Id.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }