Ejemplo n.º 1
0
        private async Task <ReturnedSaveFuncInfo> SaveMobileAsync(SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                res.AddReturnedValue(await PhoneBookBussines.RemoveAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }

                foreach (var item in TellList)
                {
                    item.ParentGuid = Guid;
                    item.Name       = Name;
                }

                res.AddReturnedValue(await PhoneBookBussines.SaveRangeAsync(TellList, tr));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private async Task <ReturnedSaveFuncInfo> SaveMobileAsync(SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                res.AddReturnedValue(await PhoneBookBussines.RemoveAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var tellList = new List <PhoneBookBussines>();
                if (!string.IsNullOrEmpty(Mobile1))
                {
                    var mob1 = new PhoneBookBussines()
                    {
                        Guid       = Guid.NewGuid(),
                        Modified   = DateTime.Now,
                        Status     = true,
                        Name       = Name,
                        ParentGuid = Guid,
                        Tell       = Mobile1,
                        Group      = EnPhoneBookGroup.Advisor
                    };
                    tellList.Add(mob1);
                }
                if (!string.IsNullOrEmpty(Mobile2))
                {
                    var mob1 = new PhoneBookBussines()
                    {
                        Guid       = Guid.NewGuid(),
                        Modified   = DateTime.Now,
                        Status     = true,
                        Name       = Name,
                        ParentGuid = Guid,
                        Tell       = Mobile2,
                        Group      = EnPhoneBookGroup.Advisor
                    };
                    tellList.Add(mob1);
                }
                res.AddReturnedValue(await PhoneBookBussines.SaveRangeAsync(tellList, tr));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }