Beispiel #1
0
        public GeneralResponse DeleteCenter(IEnumerable <DeleteRequest> requests)
        {
            GeneralResponse response = new GeneralResponse();

            foreach (var request in requests)
            {
                Center center = new Center();
                center = _centerRepository.FindBy(request.ID);

                if (center != null)
                {
                    try
                    {
                        #region Remove Dependencies
                        Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
                        Criterion criterion = new Criterion("Center.ID", center.ID, CriteriaOperator.Equal);
                        query.Add(criterion);
                        IEnumerable <Code> codesOfThisCenter = _codeRepository.FindBy(query);

                        if (codesOfThisCenter != null)
                        {
                            _codeRepository.Remove(codesOfThisCenter);
                        }

                        Infrastructure.Querying.Query query2 = new Infrastructure.Querying.Query();
                        Criterion criterion2 = new Criterion("Center.ID", center.ID, CriteriaOperator.Equal);
                        query.Add(criterion);
                        IEnumerable <NetworkCenter> networkCenters = _networkCenterRepository.FindBy(query);

                        if (networkCenters != null)
                        {
                            _networkCenterRepository.Remove(networkCenters);
                        }
                        _uow.Commit();
                        #endregion

                        _centerRepository.Remove(center);
                        _uow.Commit();
                    }
                    catch (Exception ex)
                    {
                        response.ErrorMessages.Add(ex.Message);
                        if (ex.InnerException != null)
                        {
                            //response.ErrorMessages.Add("INNER EX: " + ex.InnerException.Message);
                            response.ErrorMessages.Add("این مرکز شامل یک یا تعدادی مشتری ثبت شده میباشد");
                        }

                        return(response);
                    }
                }
                else
                {
                    response.ErrorMessages.Add("NoItemToDeleteKey");
                    return(response);
                }
            }

            return(response);
        }
Beispiel #2
0
 private ResponseEntityVM GetCodeListMapped(string code)
 {
     try
     {
         var codeList = _repository.FindBy(x => x.CodeCategory.Code.Equals(code)).ToList();
         return(new ResponseEntityVM()
         {
             StatusCode = System.Net.HttpStatusCode.OK, Result = _mapper.Map <IList <CodeVM> >(codeList)
         });
     }
     catch (Exception ex)
     {
         return(new ResponseEntityVM()
         {
             StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = $"There was an error getting the Codes: {ex.Message}"
         });
     }
 }
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);
        }