コード例 #1
0
        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 UnitOfWork.Contract.RemoveAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var sanad = await SanadBussines.GetAsync(SanadNumber);

                if (sanad != null)
                {
                    res.AddReturnedValue(await sanad.RemoveAsync(tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

                res.AddReturnedValue(await UserLogBussines.SaveAsync(EnLogAction.Delete, EnLogPart.Contracts, tr));
                if (res.HasError)
                {
                    return(res);
                }

                //if (Cache.IsSendToServer)
                //    _ = Task.Run(() => WebContract.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);
        }
コード例 #2
0
        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);
                }

                res.AddReturnedValue(await UnitOfWork.BuildingOption.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = IsModified ? EnLogAction.Update : EnLogAction.Insert;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.BuildingOptions, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebBuildingOptions.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);
        }
コード例 #3
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();
                }


                res.AddReturnedValue(await UnitOfWork.Building.ChangeStatusAsync(this, status, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = status ? EnLogAction.Enable : EnLogAction.Delete;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Building, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebBuilding.SaveAsync(this, Cache.Path));
                }
            }
            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);
        }
コード例 #4
0
        public static async Task <ReturnedSaveFuncInfo> SaveAsync(EnLogAction action, EnLogPart part, SqlTransaction tr)
        {
            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 log = new UserLogBussines
                {
                    Guid        = Guid.NewGuid(),
                    UserGuid    = UserBussines.CurrentUser.Guid,
                    Description =
                        $"انجام عملیات {action.GetDisplay()} در بخش {part.GetDisplay()} در تاریخ {Calendar.MiladiToShamsi(DateTime.Now)} در ساعت {DateTime.Now.ToShortTimeString()}",
                    Action = action,
                    Part   = part
                };
                res.AddReturnedValue(await UnitOfWork.UserLog.SaveAsync(log, tr));
            }
            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);
        }
コード例 #5
0
        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);
                }

                if (OptionList.Count > 0)
                {
                    res.AddReturnedValue(await BuildingRelatedOptionsBussines.RemoveRangeAsync(Guid, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }

                    foreach (var item in OptionList)
                    {
                        item.BuildinGuid = Guid;
                    }
                    res.AddReturnedValue(await BuildingRelatedOptionsBussines.SaveRangeAsync(OptionList, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }
                if (GalleryList.Count > 0)
                {
                    res.AddReturnedValue(await BuildingGalleryBussines.RemoveRangeAsync(Guid, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }

                    foreach (var item in GalleryList)
                    {
                        item.BuildingGuid = Guid;
                    }

                    res.AddReturnedValue(await BuildingGalleryBussines.SaveRangeAsync(GalleryList, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }


                res.AddReturnedValue(await UnitOfWork.Building.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = IsModified ? EnLogAction.Update : EnLogAction.Insert;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Building, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebBuilding.SaveAsync(this, Cache.Path));
                }
            }
            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);
        }
コード例 #6
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.Peoples.ChangeStatusAsync(this, status, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = status ? EnLogAction.Enable : EnLogAction.Delete;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Peoples, tr));
                if (res.HasError)
                {
                    return(res);
                }

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