示例#1
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 list = await PeoplesBussines.GetAllAsync(Guid, false, new CancellationToken());

                foreach (var item in list)
                {
                    item.GroupGuid = Guid.Empty;
                    res.AddReturnedValue(await UnitOfWork.Peoples.SaveAsync(item, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

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

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebPeopleGroup.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);
        }
        public static async Task <List <BuildingViewModel> > GetAllAsync(string code, CancellationToken token, Guid buildingGuid,
                                                                         Guid buildingAccountTypeGuid, int fMasahat, int lMasahat, int roomCount, decimal fPrice1, decimal lPrice1,
                                                                         decimal fPrice2, decimal lPrice2, EnRequestType type, List <Guid> regionList)
        {
            try
            {
                IEnumerable <BuildingBussines> res = await GetAllAsync(token);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (regionList != null && regionList.Count > 0)
                {
                    res = res.Where(q => regionList.Contains(q.RegionGuid));
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (!string.IsNullOrEmpty(code))
                {
                    res = res.Where(q => q.Code.Contains(code));
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (buildingGuid != Guid.Empty)
                {
                    res = res.Where(q => q.BuildingTypeGuid == buildingGuid);
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (buildingAccountTypeGuid != Guid.Empty)
                {
                    res = res.Where(q => q.BuildingAccountTypeGuid == buildingAccountTypeGuid);
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (fMasahat != 0)
                {
                    res = res.Where(q => q.Masahat >= fMasahat);
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (lMasahat != 0)
                {
                    res = res.Where(q => q.Masahat <= lMasahat);
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (roomCount != 0)
                {
                    res = res.Where(q => q.RoomCount <= roomCount);
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                if (type == EnRequestType.Rahn)
                {
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    if (fPrice1 != 0)
                    {
                        res = res.Where(q => q.RahnPrice1 >= fPrice1);
                    }
                    if (fPrice2 != 0)
                    {
                        res = res.Where(q => q.RahnPrice2 <= fPrice2);
                    }
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    if (lPrice1 != 0)
                    {
                        res = res.Where(q => q.EjarePrice1 >= lPrice1);
                    }
                    if (lPrice2 != 0)
                    {
                        res = res.Where(q => q.EjarePrice2 <= lPrice2);
                    }
                }
                else
                {
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    if (fPrice1 != 0)
                    {
                        res = res.Where(q => q.SellPrice > 0 && q.SellPrice >= fPrice1);
                    }
                    if (fPrice2 != 0)
                    {
                        res = res.Where(q => q.SellPrice > 0 && q.SellPrice <= fPrice2);
                    }
                }
                if (token.IsCancellationRequested)
                {
                    return(null);
                }
                var val = new List <BuildingViewModel>();

                foreach (var item in res)
                {
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    var a = new BuildingViewModel()
                    {
                        RoomCount       = item.RoomCount.ToString(),
                        SaleSakht       = item.SaleSakht,
                        Tabaqe          = $"{item.TabaqeNo} از {item.TedadTabaqe}",
                        Description     = item.ShortDesc,
                        Metrazh         = item.Masahat,
                        Region          = item.RegionName,
                        RentalAuthority = item.RentalAuthorityName,
                        Parent          = $"فایل های سیستم کد {item.Code}",
                        Options         = item.OptionList.Select(q => q.OptionName)?.ToList(),
                        Address         = item.Address,
                        Mobile          = PeoplesBussines.Get(item.OwnerGuid)?.FirstNumber
                    };
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    if (type == EnRequestType.Rahn)
                    {
                        a.Price1 = item.RahnPrice1;
                        a.Price2 = item.EjarePrice1;
                        if (item.RahnPrice2 != 0)
                        {
                            a.Tabdil = item.RahnPrice2 + "ریال ودیعه";
                        }
                        if (item.EjarePrice2 != 0)
                        {
                            a.Tabdil = a.Tabdil + item.EjarePrice2 + "ریال ودیعه";
                        }
                        if (item.RahnPrice2 == 0 && item.EjarePrice2 == 0)
                        {
                            a.Tabdil = "غیرقابل تبدیل";
                        }
                        a.Type = EnRequestType.Rahn;
                    }
                    else
                    {
                        if (token.IsCancellationRequested)
                        {
                            return(null);
                        }
                        a.Price1 = item.SellPrice;
                        a.Price2 = 0;
                        a.Type   = EnRequestType.Forush;
                    }
                    val.Add(a);
                }

                return(val);
            }
            catch (TaskCanceledException) { return(null); }
            catch (OperationCanceledException) { return(null); }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                return(new List <BuildingViewModel>());
            }
        }