public async Task <ReturnedSaveFuncInfo> RemoveAsync(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();
                }

                res.AddReturnedValue(await UpdateAccounts(Details, true, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await SanadDetailBussines.RemoveRangeAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await UnitOfWork.Sanad.RemoveAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }

                //if (Cache.IsSendToServer)
                //    _ = Task.Run(() => WebRental.SaveAsync(list));
            }
            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);
        }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(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();
                }

                res.AddReturnedValue(await CheckvalidationAsync());
                if (res.HasError)
                {
                    return(res);
                }

                var oldSanad = await GetAsync(Guid);

                if (oldSanad != null)
                {
                    res.AddReturnedValue(await UpdateAccounts(oldSanad.Details, true, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

                res.AddReturnedValue(await UnitOfWork.Sanad.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }
                foreach (var item in Details)
                {
                    item.MasterGuid = Guid;
                }
                res.AddReturnedValue(await SanadDetailBussines.RemoveRangeAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await SanadDetailBussines.SaveRangeAsync(Details, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await UpdateAccounts(Details, false, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebSanad.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);
        }