Ejemplo n.º 1
0
        public ICommandResult Handle(GenerateCustomerCodeCommand command)
        {
            //Validar command
            command.Validate();

            if (!_customerRepository.CheckEmail(command.Email))
            {
                return(new GenericCommandResult());
            }

            var customer = _customerRepository.GetByEmail(command.Email);

            //Criar entidades
            var code = new Code(customer.Id);

            //Persistir no banco
            _codeRepository.Save(code);

            //Enviar sms
            _smsService.Send(customer.Phone, $"Codigo plataforma Controle Financeiro:\n\n{code.CodeValue}\n\n\n");

            return(new GenericCommandResult(true, $"Código de validação enviado para o numero {customer.Phone}", null));
        }
Ejemplo n.º 2
0
        public GeneralResponse EditCode(EditCodeRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();
            Code            code     = new Code();

            code = _codeRepository.FindBy(request.ID);

            if (code != null)
            {
                try
                {
                    code.ModifiedDate     = PersianDateTime.Now;
                    code.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    code.Center           = _centerRepository.FindBy(request.CenterID);
                    //string oldCode = code.CodeName;
                    code.CodeName = request.CodeName;

                    #region RowVersion
                    if (code.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        code.RowVersion += 1;
                    }
                    #endregion

                    #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)
                    if (_codeRepository.FindBy(query) != null)
                    {
                        //Code exitstCode = _codeRepository.FindBy(query).FirstOrDefault();
                        //response.ErrorMessages.Add(String.Format("این پیش شماره قبلاً برای مرکز مخابراتی «{0}» به ثبت رسیده است.", exitstCode.Center.CenterName));
                        response.ErrorMessages.Add("DuplicateCode");
                        return(response);
                    }

                    #endregion

                    #region Update Center Of Customers if exist any

                    //// customers of New Code
                    //IEnumerable<Customer> customers = _customerRepository.FindBy(code.CodeName);
                    //Center center = _centerRepository.FindBy(request.CenterID);

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

                    //// Customers of Old Code
                    //customers = _customerRepository.FindBy(oldCode);

                    //if (customers != null && customers.Count() > 0)
                    //{
                    //    foreach (Customer customer in customers)
                    //    {
                    //        customer.Center = null;
                    //        _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.Save(code);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }