private async Task <ReturnedSaveFuncInfo> SaveTafsilAsync(SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var tf = await TafsilBussines.GetAsync(Guid) ?? new TafsilBussines
                {
                    Guid      = Guid,
                    DateM     = DateM,
                    Account   = 0,
                    HesabType = HesabType.Bank,
                    Modified  = Modified,
                    Status    = true,
                    isSystem  = false
                };

                tf.Code         = Code;
                tf.Name         = Name;
                tf.Description  = Description;
                tf.AccountFirst = AccountFirst;

                res.AddReturnedValue(await tf.SaveAsync(tr));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
        public async Task <ReturnedSaveFuncInfo> ChangeStatusAsync(bool status, SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                var tafsil = await TafsilBussines.GetAsync(Guid);

                if (tafsil == null)
                {
                    res.AddError("حساب انتخاب شده معتبر نمی باشد");
                    return(res);
                }

                res.AddReturnedValue(await tafsil.ChangeStatusAsync(status, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await PhoneBookBussines.ChangeStatusAsync(Guid, status, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await UnitOfWork.Advisor.ChangeStatusAsync(this, status, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebAdvisor.SaveAsync(this));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        private static async Task <ReturnedSaveFuncInfo> UpdateAccounts(List <SanadDetailBussines> dets, bool isRemove, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                foreach (var item in dets)
                {
                    var tafsil = await TafsilBussines.GetAsync(item.TafsilGuid);

                    var moein = await MoeinBussines.GetAsync(item.MoeinGuid);

                    decimal price = 0;
                    var     tag   = 1;
                    if (isRemove)
                    {
                        tag *= -1;
                    }

                    if (item.Debit > 0)
                    {
                        price = -item.Debit * tag;
                    }
                    else if (item.Credit > 0)
                    {
                        price = item.Credit * tag;
                    }
                    else
                    {
                        res.AddError("مبلغ نامعتبر");
                        return(res);
                    }

                    if (moein == null)
                    {
                        res.AddError("حساب معین نامعتبر");
                        return(res);
                    }
                    if (tafsil == null)
                    {
                        res.AddError("حساب تفصیلی نامعتبر");
                        return(res);
                    }

                    res.AddReturnedValue(await moein.UpdateAccountAsync(price, tr));
                    res.AddReturnedValue(await tafsil.UpdateAccountAsync(price, tr));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Exemple #4
0
        private static async Task <ReturnedSaveFuncInfo> UpdateAccountsAsync(PardakhtCheckAvalDoreBussines item, bool isRemove, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var checkPage = await CheckPageBussines.GetAsync(item.CheckPageGuid);

                var dasteCheck = await DasteCheckBussines.GetAsync(checkPage.CheckGuid);

                var tafsil = await TafsilBussines.GetAsync(dasteCheck.BankGuid);

                var moein = await MoeinBussines.GetAsync(ParentDefaults.MoeinCoding.CLSMoein30101);

                decimal price = 0;
                var     tag   = 1;
                if (isRemove)
                {
                    tag *= -1;
                }

                price = item.Price * tag;

                if (moein == null)
                {
                    res.AddError("حساب معین نامعتبر");
                    return(res);
                }
                if (tafsil == null)
                {
                    res.AddError("حساب تفصیلی نامعتبر");
                    return(res);
                }

                res.AddReturnedValue(await moein.UpdateAccountAsync(price, tr));
                res.AddReturnedValue(await tafsil.UpdateAccountAsync(price, tr));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }