Exemplo n.º 1
0
        public GeneralResponse DeleteCode(IEnumerable <DeleteRequest> requests)
        {
            GeneralResponse response = new GeneralResponse();

            foreach (var request in requests)
            {
                Code code = new Code();
                code = _codeRepository.FindBy(request.ID);

                #region If used by customers can not be deleted

                IEnumerable <Customer> customers = _customerRepository.FindByPhoneCode(code.CodeName);

                if (customers != null && customers.Count() > 0)
                {
                    //foreach (Customer customer in customers)
                    //{
                    //    customer.Center = null;
                    //    _customerRepository.Add(customer);
                    //}
                    response.ErrorMessages.Add("UsedByCustomersAndCannotDelete");
                    return(response);
                }

                #endregion

                if (code != null)
                {
                    try
                    {
                        _codeRepository.Remove(code);
                    }
                    catch (Exception ex)
                    {
                        response.ErrorMessages.Add(ex.Message);
                        return(response);
                    }
                }
            }
            try
            {
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                return(response);
            }

            return(response);
        }
Exemplo n.º 2
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);
        }