Beispiel #1
0
        public GetCenterResponse GetCenter(GetRequest request)
        {
            GetCenterResponse response = new GetCenterResponse();

            try
            {
                Center center = _centerRepository.FindBy(request.ID);

                if (center != null)
                {
                    CenterView centerView = center.ConvertToCenterView();

                    Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
                    Criterion criteria = new Criterion("Center.ID", center.ID, CriteriaOperator.Equal);
                    query.Add(criteria);
                    IEnumerable <NetworkCenter>     networkCenters     = _networkCenterRepository.FindBy(query);
                    IEnumerable <NetworkCenterView> networkCenterViews = networkCenters.ConvertToNetworkCenterViews();

                    centerView.NetworkCenters = networkCenterViews;


                    response.CenterView = centerView;
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(response);
        }
        public GeneralResponse AddNetworkCenter(AddNetworkCenterRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                NetworkCenter networkCenter = new NetworkCenter();
                networkCenter.Network        = _networkRepository.FindBy(request.NetworkID);
                networkCenter.Center         = _centerRepository.FindBy(request.CenterID);
                networkCenter.CreateDate     = PersianDateTime.Now;
                networkCenter.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                networkCenter.Status         = (NetworkCenterStatus)request.Status;
                networkCenter.CanSale        = request.CanSale;
                networkCenter.RowVersion     = 1;

                _networkCenterRepository.Add(networkCenter);
                _uow.Commit();

                ////response.success = true;

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

                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }
Beispiel #3
0
        public GeneralResponse AddCode(AddCodeRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Code code = new Code();
                code.ID             = Guid.NewGuid();
                code.CreateDate     = PersianDateTime.Now;
                code.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                code.Center         = _centerRepository.FindBy(request.CenterID);
                code.CodeName       = request.CodeName;
                code.RowVersion     = 1;

                #region If Duplicate, send Error message

                Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
                Criterion criterion = new Criterion("CodeName", code.CodeName, CriteriaOperator.Equal);
                query.Add(criterion);

                if (_codeRepository.FindBy(query).Count() > 0)
                {
                    Code exitstCode = _codeRepository.FindBy(query).FirstOrDefault();
                    //response.ErrorMessages.Add(String.Format("این پیش شماره قبلاً برای مرکز مخابراتی «{0}» به ثبت رسیده است.", exitstCode.Center.CenterName));

                    response.ErrorMessages.Add("RegisteredKey" + exitstCode.Center.CenterName + "ThisPerfixKey");
                    return(response);
                }

                #endregion

                #region Update Center Of Customers if exist any

                IEnumerable <Customer> customers = _customerRepository.FindByPhoneCode(code.CodeName);
                Center center = _centerRepository.FindBy(request.CenterID);

                if (customers.Count() > 0)
                {
                    foreach (Customer customer in customers)
                    {
                        customer.Center = center;
                        _customerRepository.Save(customer);
                    }
                }

                #endregion

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

                    return(response);
                }
                #endregion

                _codeRepository.Add(code);
                _uow.Commit();

                ////response.success = true;
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }