示例#1
0
        public GetCenterInfoResponse GetCenterInfo(string adslPhone, int codeLengh)
        {
            GetCenterInfoResponse response = new GetCenterInfoResponse();

            try
            {
                IList <Center> centers = new List <Center>();

                response.hasCenter = false;

                // اگر مقدار تلفن عددی نبود هیچ عملیاتی انجام نده
                int adslInt = -1;
                if (!int.TryParse(adslPhone, out adslInt))
                {
                    response.hasCenter = false;
                    return(response);
                }

                // اگر شماره خاص بود اینجا مشخص می شود
                string HqlSpecial = string.Format("From SpecialNumber s where s.FromNumber <= {0} and s.ToNumber >= {0}", adslInt);
                IEnumerable <SpecialNumber> specialNumbers = _specialNumberRepository.FindAll(HqlSpecial).data;
                if (specialNumbers.Count() > 0)
                {
                    response.Status    = "عدم پوشش (شماره خاص)‏";
                    response.hasCenter = true;
                }

                // یافتن مرکز مخابراتی
                string Hql = String.Format(@"Select c From Code co Join co.Center c Where co.CodeName Like {0}%", adslPhone.Substring(0, codeLengh));
                centers = _centerRepository.FindAll(Hql).data.ToList();

                if (centers.Count == 1)
                {
                    Center center = centers.FirstOrDefault();

                    // agar shomareye khas bashad hasCenter = true ast va Status nabayad por shavad
                    if (!response.hasCenter)
                    {
                        response.Status = center.Status;
                    }

                    response.CenterName = center.ConvertToCenterView().CenterName;
                    response.CenterID   = center.ID;
                    response.Center     = center;
                    response.hasCenter  = true;
                }
                else
                {
                    response.hasCenter = false;
                }
            }
            catch (Exception ex)
            {
                response.Status    = "ConnectionError‏";
                response.hasCenter = false;
                return(response);
            }

            return(response);
        }
        public GeneralResponse UpdateAll()
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                var centers  = _centerRepository.FindAll();
                var networks = _networkRepository.FindAll();
                foreach (var center in centers)
                {
                    int counter = 0;
                    foreach (var network in networks)
                    {
                        counter++;
                        NetworkCenterPriority networkCenterPriority = new NetworkCenterPriority();
                        networkCenterPriority.Center       = center;
                        networkCenterPriority.Network      = network;
                        networkCenterPriority.SalePriority = counter;
                        _networkCenterPriorityRepository.Add(networkCenterPriority);
                    }
                }
                _uow.Commit();
            }

            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
示例#3
0
        public GeneralResponse AddNetwork(AddNetworkRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Network network = new Network();
                network.ID                   = Guid.NewGuid();
                network.CreateDate           = PersianDateTime.Now;
                network.CreateEmployee       = _employeeRepository.FindBy(request.CreateEmployeeID);
                network.DeliverWhenCreditLow = request.DeliverWhenCreditLow;
                network.NetworkName          = request.NetworkName;
                network.Note                 = request.Note;

                network.RowVersion = 1;

                // Validation
                if (network.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in network.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                // be jaye Triggere After Insert. NetworkCenter-ha insert mishavad
                IList <NetworkCenter> networkCenters = new List <NetworkCenter>();
                foreach (Center center in _centerRepository.FindAll())
                {
                    NetworkCenter networkCenter = new NetworkCenter();
                    networkCenter.Network        = network;
                    networkCenter.Center         = center;
                    networkCenter.CreateDate     = PersianDateTime.Now;
                    networkCenter.CreateEmployee = network.CreateEmployee;
                    networkCenter.Status         = NetworkCenterStatus.NotDefined;
                    networkCenter.RowVersion     = 1;

                    networkCenters.Add(networkCenter);
                }

                network.NetworkCenters = networkCenters;
                _networkRepository.Add(network);

                _uow.Commit();

                ////response.success = true;
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add("FIRST INNER EXPCEPTION: " + ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        response.ErrorMessages.Add("SECOND INNER EXPCEPTION: " + ex.InnerException.InnerException.Message);
                    }
                }
            }

            return(response);
        }