Ejemplo n.º 1
0
        public IActionResult Update([FromBody] dynamic payeeData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (payeeData != null)
                {
                    Lms_PayeePoco payeePoco = JsonConvert.DeserializeObject <Lms_PayeePoco>(JsonConvert.SerializeObject(payeeData[0]));

                    if (payeePoco.Id > 0 && payeePoco.PayeeName.Trim() != string.Empty)
                    {
                        using (var scope = new TransactionScope())
                        {
                            var existingPayee = _payeeLogic.GetSingleById(payeePoco.Id);
                            if (existingPayee != null)
                            {
                                existingPayee.PayeeName    = payeePoco.PayeeName;
                                existingPayee.Address      = payeePoco.Address;
                                existingPayee.EmailAddress = payeePoco.EmailAddress;
                                existingPayee.PhoneNumber  = payeePoco.PhoneNumber;
                                _payeeLogic.Update(existingPayee);

                                result = existingPayee.Id.ToString();
                            }

                            scope.Complete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }
Ejemplo n.º 2
0
        public IActionResult Add([FromBody] dynamic payeeData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (payeeData != null)
                {
                    Lms_PayeePoco payeePoco = JsonConvert.DeserializeObject <Lms_PayeePoco>(JsonConvert.SerializeObject(payeeData[0]));

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

                        var parentGLForBillAccount = _configurationLogic.GetSingleById(1).ParentGLForBillPayable;
                        var newAccountId           = (int)parentGLForBillAccount;
                        var accounts = _chartOfAccountLogic.GetList().Where(c => c.ParentGLCode == parentGLForBillAccount).ToList();
                        if (accounts.Count > 0)
                        {
                            newAccountId = accounts.Max(c => c.Id);
                        }

                        newAccountId += 1;

                        using (var scope = new TransactionScope())
                        {
                            Lms_ChartOfAccountPoco accountPoco = new Lms_ChartOfAccountPoco();
                            accountPoco.Id             = newAccountId;
                            accountPoco.ParentGLCode   = parentGLForBillAccount;
                            accountPoco.AccountName    = payeePoco.PayeeName;
                            accountPoco.BranchId       = sessionData.BranchId == null ? 1 : (int)sessionData.BranchId;
                            accountPoco.CurrentBalance = 0;
                            accountPoco.IsActive       = true;
                            accountPoco.Remarks        = "Payee Account Payable";
                            accountPoco.CreateDate     = DateTime.Now;
                            accountPoco.CreatedBy      = sessionData.UserId;

                            var addedAcc = _chartOfAccountLogic.Add(accountPoco);
                            if (addedAcc.Id > 0)
                            {
                                payeePoco.AccountNo = addedAcc.Id.ToString();
                                var payeeId = _payeeLogic.Add(payeePoco).Id;

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

            return(Json(result));
        }