コード例 #1
0
ファイル: WebDeploySource.cs プロジェクト: kjelliverb/ConDep
        public bool IsValid(Notification notification)
        {
            _credentials.IsValid(notification);

            if (!LocalHost && string.IsNullOrWhiteSpace(ComputerName) && string.IsNullOrWhiteSpace(PackagePath))
            {
                notification.AddError(new SemanticValidationError("Neither localhost or computer name is defined for source.", ValidationErrorType.NoSource));
                return true;
            }
            return false;
        }
コード例 #2
0
        public virtual Notification validateForSave()
        {
            Notification notification = new Notification();

            if (this == null)
            {
                notification.AddError("Provider is null");
            }

            return(notification);
        }
コード例 #3
0
        private Notification Validation(BankAccountInputDto entity)
        {
            Notification notification = new Notification();

            if (entity == null)
            {
                notification.AddError("Invalid JSON data in request body.");

                return(notification);
            }

            if (string.IsNullOrEmpty(entity.Number))
            {
                notification.AddError("Bank Account Number is missing");
            }
            else if (entity.Number.Length != 18)
            {
                notification.AddError("Bank Account Number should have 18 numbers");
            }
            return(notification);
        }
コード例 #4
0
        private Notification ValidateModel(AuthenticationDTO model)
        {
            Notification notification = new Notification();

            if (model == null)

            {
                notification.AddError("Invalid JSON data in request body");
                return(notification);
            }

            return(notification);
        }
コード例 #5
0
        private Notification ValidationUpdate(BankAccountInputUpdateDto entity)
        {
            Notification notification = new Notification();

            if (entity == null)
            {
                notification.AddError("Invalid JSON data in request body.");

                return(notification);
            }

            return(notification);
        }
コード例 #6
0
 public override bool IsValid(Notification notification)
 {
     try
     {
         var uri = new Uri(_url);
     }
     catch (Exception ex)
     {
         notification.AddError(new ValidationError(ex.Message));
         return(false);
     }
     return(true);
 }
コード例 #7
0
        private Notification ValidateModel(CategoryCreateDto model)
        {
            Notification notification = new Notification();

            if (model == null || string.IsNullOrEmpty(model.Name))

            {
                notification.AddError("Invalid JSON data in request body");
                return(notification);
            }

            return(notification);
        }
コード例 #8
0
        private Notification ValidateRegistration(RegisterDto model)
        {
            Notification notification = new Notification();

            if (model == null || string.IsNullOrEmpty(model.Email) ||
                string.IsNullOrEmpty(model.UserName) ||
                string.IsNullOrEmpty(model.Password)
                )

            {
                notification.AddError("Invalid JSON data in request body");
                return(notification);
            }

            if (model.UserName.Length < int.Parse(_config["Account:UserNameRequiredLength"]))
            {
                notification.AddError($"UserName must have at least {_config["Account:UserNameRequiredLength"]} characters.");
                return(notification);
            }

            return(notification);
        }
コード例 #9
0
        public virtual Notification CanWithdrawMoney(decimal amount)
        {
            Notification notification = new Notification();

            if (amount <= 0)
            {
                notification.AddError(AccountConstants.AmountMustBeGreaterThanZero);
            }
            if (!HasIdentity())
            {
                notification.AddError(AccountConstants.AccountHasNoIdentity);
            }
            if (Locked)
            {
                notification.AddError(AccountConstants.AccountIsLocked);
            }
            if (!CanBeWithdrawed(amount))
            {
                notification.AddError(AccountConstants.CannotWithdrawAmountIsGreaterThanBalance);
            }
            return(notification);
        }
コード例 #10
0
        private Notification Validation(CredentialInputDto credential)
        {
            Notification notification = new Notification();

            if (credential == null)
            {
                notification.AddError("Invalid JSON data in request body.");
                return(notification);
            }

            if (string.IsNullOrEmpty(credential.UserName))
            {
                notification.AddError("UserName is missing");
            }

            if (string.IsNullOrEmpty(credential.Password))
            {
                notification.AddError("Password is missing");
            }

            return(notification);
        }
コード例 #11
0
        public IActionResult Create([FromBody] CustomerDto customerDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Customer customer = _customerAssembler.FromCustomerDtoToCustomer(customerDto);
                notification = customer.ValidateForSave();

                if (notification.HasErrors())
                {
                    logger.Message(notification.ErrorMessage(), LogLevel.FunctionalError);
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                Specification <Customer> specification = GetUniqueCustomer(customer.Document_Number);
                var uniqueCustomer = _customerRepository.GetUniqueCustomer(specification);

                if (uniqueCustomer != null)
                {
                    notification.AddError("Customer already registered");
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                customer.Status = 1;
                _customerRepository.Create(customer);
                _unitOfWork.Commit(uowStatus);

                var message = "Customer " + customer.Id + " created!";
                KipubitRabbitMQ.SendMessage(message);
                logger.Message(message, LogLevel.FunctionalMessage);

                return(Ok(responseHandler.getOkCommandResponse(message, StatusCodes.Status201Created)));
            }
            catch (ArgumentException ex)
            {
                logger.Message(ex.Message, LogLevel.Error);
                return(BadRequest(responseHandler.getAppCustomErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                logger.Message(ex.StackTrace, LogLevel.Debug);
                return(StatusCode(StatusCodes.Status500InternalServerError, responseHandler.getAppExceptionResponse()));
            }
        }
コード例 #12
0
        public bool SignUp(AuthenticationDTO model)
        {
            Notification notification = ValidateModel(model);

            if (notification.HasErrors())
            {
                throw new ArgumentException(notification.ErrorMessage());
            }

            bool status = _unitOfWork.BeginTransaction();

            try
            {
                Organization organization = _authenticationCreateAssembler.ToOrganizationEntity(model);

                _organizationRepository.Create(organization);


                var newRole = new Role {
                    Name = "Owner"
                };

                _roleRepository.Create(newRole);

                User user = _authenticationCreateAssembler.ToUserEntity(model);
                user.Role         = newRole;
                user.Organization = organization;

                _userRepository.Create(user);

                Project project = _authenticationCreateAssembler.ToProjectEntity(model);

                project.Organization = organization;

                _projectRepository.Create(project);

                _unitOfWork.Commit(status);
            }
            catch
            {
                _unitOfWork.Rollback(status);

                notification.AddError("there was error creating product");
                throw new ArgumentException(notification.ErrorMessage());
            }


            return(true);
        }
コード例 #13
0
        public void AddThing(Thing thing)
        {
            if (thing is null)
            {
                return;
            }

            if (thing.Valid == false)
            {
                Notification.AddError(DomainResource.Whatever_Thing_invalid, thing.Notification);
                return;
            }

            Things.Add(thing);
        }
コード例 #14
0
        public Notification CanPerformTransfer(Account originAccount, Account destinationAccount, decimal amount)
        {
            Notification notification = new Notification();

            if (amount <= 0)
            {
                notification.AddError(TransactionConstants.AmountMustBeGreaterThanZero);
            }
            if (originAccount == null)
            {
                notification.AddError(TransactionConstants.OriginAccountInvalid);
            }
            if (destinationAccount == null)
            {
                notification.AddError(TransactionConstants.DestinationAccountInvalid);
            }
            if (originAccount != null &&
                destinationAccount != null &&
                originAccount.Number.Equals(destinationAccount.Number))
            {
                notification.AddError(TransactionConstants.CannotTransferSameAccounts);
            }
            return(notification);
        }
コード例 #15
0
        public void SetNeighborhood(string neighborhood)
        {
            if (string.IsNullOrWhiteSpace(neighborhood))
            {
                Notification.AddError(DomainGeneralValueObjectsNotificationMessages.Address_Neighborhood_Empty);
                return;
            }

            if (neighborhood.Length > NeighborhoodMaxLength)
            {
                Notification.AddError(string.Format(DomainGeneralValueObjectsNotificationMessages.Address_Neighborhood_MaxLengthOverflow, NeighborhoodMaxLength));
                return;
            }

            Neighborhood = neighborhood;
        }
コード例 #16
0
        public void SetComplement(string complement)
        {
            if (string.IsNullOrWhiteSpace(complement))
            {
                Complement = null;
                return;
            }

            if (complement.Length > ComplementMaxLength)
            {
                Notification.AddError(string.Format(DomainGeneralValueObjectsNotificationMessages.Address_Complement_MaxLengthOverflow, ComplementMaxLength));
                return;
            }

            Complement = complement;
        }
コード例 #17
0
        public void SetCity(City city)
        {
            if (city is null)
            {
                Notification.AddError(DomainGeneralValueObjectsNotificationMessages.Address_City_Empty);
                return;
            }

            if (!city.IsValid())
            {
                Notification.AddError(city.Notification);
                return;
            }

            City = city;
        }
コード例 #18
0
        private async Task <Notification> EnsureUniqueLIN(Guid id, string lin, IQueryBus queryBus)
        {
            var result = await queryBus.PublishAsync(new GetMasterByLINQuery { LIN = lin });

            var master = (result.Result as IEnumerable <InventoryMaster>)
                         .FirstOrDefault(x => x.AggregateRootId != id);

            var notification = new Notification();

            if (master != null)
            {
                notification.AddError($"The LIN '{lin}' is already in use by item '{master.GeneralNomenclature}'", "LIN");
            }

            return(notification);
        }
コード例 #19
0
        private void SetState(State state)
        {
            if (state is null)
            {
                Notification.AddError(DomainGeneralValueObjectsNotificationMessages.City_State_Empty);
                return;
            }

            if (!state.IsValid())
            {
                Notification.AddError(state.Notification);
                return;
            }

            State = state;
        }
コード例 #20
0
        public void SetZipCode(ZipCode zipCode)
        {
            if (zipCode is null)
            {
                Notification.AddError(DomainGeneralValueObjectsNotificationMessages.Address_ZipCode_Empty);
                return;
            }

            if (!zipCode.IsValid())
            {
                Notification.AddError(zipCode.Notification);
                return;
            }

            ZipCode = zipCode;
        }
コード例 #21
0
        private void SetName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                Notification.AddError(DomainGeneralValueObjectsNotificationMessages.State_Name_Empty);
                return;
            }

            if (name.Length > NameMaxLength)
            {
                Notification.AddError(string.Format(DomainGeneralValueObjectsNotificationMessages.State_Name_MaxLengthOverflow, NameMaxLength));
                return;
            }

            Name = name;
        }
コード例 #22
0
        public static Try <Notification, string> GetHelloType(int identifier)
        {
            var notification = new Notification(NotificationDelimiter.WebDelimiter);

            if (identifier <= 0)
            {
                notification.AddError("O identificador informado é inválido.");
            }

            if (notification.HasError)
            {
                return(notification);
            }

            var helloPersonID = string.Format("Hello World: {0}ID!", identifier);

            return(helloPersonID);
        }
コード例 #23
0
        public IActionResult Update(int CustomerId, [FromBody] CustomerDto CustomerDto)
        {
            Notification notification = new Notification();

            if (CustomerId == 0)
            {
                notification.AddError("CustomerId is missing");
                return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
            }

            bool uowStatus = false;

            try
            {
                Customer customer = new Customer();
                uowStatus    = _unitOfWork.BeginTransaction();
                customer     = _customerAssembler.FromCustomerDtoToCustomer(CustomerDto);
                customer.Id  = CustomerId;
                notification = customer.ValidateForSave("U");

                ThrowErrors(notification);

                if (notification.HasErrors())
                {
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                _customerRepository.Update(customer);
                _unitOfWork.Commit(uowStatus);

                var message = "Customer " + CustomerId + " updated!";
                return(Ok(responseHandler.getOkCommandResponse(message, StatusCodes.Status200OK)));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(responseHandler.getAppCustomErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, responseHandler.getAppExceptionResponse()));
            }
        }
コード例 #24
0
        public async Task <bool> ValidateOrganization(Notification Notification)
        {
            if (Notification.OrganizationId != null && Notification.OrganizationId != 0)
            {
                OrganizationFilter OrganizationFilter = new OrganizationFilter
                {
                    Id = new IdFilter {
                        Equal = Notification.OrganizationId
                    }
                };
                int count = await UOW.OrganizationRepository.Count(OrganizationFilter);

                if (count == 0)
                {
                    Notification.AddError(nameof(NotificationValidator), nameof(Notification.Organization), ErrorCode.OrganizationIdNotExisted);
                }
            }
            return(Notification.IsValidated);
        }
コード例 #25
0
        public async Task <bool> ValidateId(Notification Notification)
        {
            NotificationFilter NotificationFilter = new NotificationFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = Notification.Id
                },
                Selects = NotificationSelect.Id
            };

            int count = await UOW.NotificationRepository.Count(NotificationFilter);

            if (count == 0)
            {
                Notification.AddError(nameof(NotificationValidator), nameof(Notification.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
コード例 #26
0
        public IActionResult Update(int ProductId, [FromBody] ProductDto ProductDto)
        {
            Notification notification = new Notification();

            if (ProductId == 0)
            {
                notification.AddError("ProductId is missing");
                return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
            }

            bool uowStatus = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Product product = _ProductAssembler.FromProductDtoToProduct(ProductDto);
                product.Id   = ProductId;
                notification = product.ValidateForSave("U");

                if (notification.HasErrors())
                {
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }
                _ProductRepository.Update(product);
                _unitOfWork.Commit(uowStatus);

                var message = "Product " + ProductId + " updated!";
                return(Ok(responseHandler.getOkCommandResponse(message, StatusCodes.Status200OK)));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(responseHandler.getAppCustomErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, responseHandler.getAppExceptionResponse()));
            }
        }
        public Notification <bool> CreateEvent(Event ev)
        {
            ev.SetId(GetMaxId() + 1);
            EventValidator      validator = new EventValidator(ev);
            bool                valid     = validator.Validate();
            Notification <bool> notifier  = new Notification <bool>();

            if (!valid)
            {
                foreach (var error in validator.GetErrors())
                {
                    notifier.AddError(error);
                }
                notifier.SetResult(false);
            }
            else
            {
                notifier.SetResult(eventRepo.Create(ev));
            }
            return(notifier);
        }
コード例 #28
0
        public bool SignUp(UserCreateDto model)
        {
            Notification notification = ValidateModel(model);

            if (notification.HasErrors())
            {
                throw new ArgumentException(notification.ErrorMessage());
            }

            bool status = _unitOfWork.BeginTransaction();

            try
            {
                var memberRole = _roleRepository.GetByName(Roles.Member);

                if (memberRole == null)
                {
                    memberRole = new Role {
                        Name = Roles.Member
                    };

                    _roleRepository.Create(memberRole);
                }

                User user = _userCreateAssembler.ToUserEntity(model);
                user.Role = memberRole;
                _userRepository.Create(user);

                _unitOfWork.Commit(status);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(status);

                notification.AddError("there was error creating user");
                throw new ArgumentException(notification.ErrorMessage());
            }
            return(true);
        }
コード例 #29
0
        public Notification <bool> Register(User user)
        {
            UserValidator       userValidator = new UserValidator(user);
            bool                userValid     = userValidator.Validate();
            Notification <bool> notifier      = new Notification <bool>();

            if (!userValid)
            {
                foreach (var error in userValidator.GetErrors())
                {
                    notifier.AddError(error);
                }
                notifier.SetResult(false);
            }
            else
            {
                user.SetId(GetMaxId() + 1);
                user.SetPassword(EncodePassword(user.GetPassword()));
                notifier.SetResult(userRepo.Create(user));
            }
            return(notifier);
        }
コード例 #30
0
ファイル: Usuario.cs プロジェクト: eduVeras/fiap-closerain
        public Notification <Usuario> IsValid()
        {
            var notification = new Notification <Usuario>(this);

            if (string.IsNullOrWhiteSpace(Nome))
            {
                notification.AddError(nameof(Nome), "Nome deve ser preenchido.");
            }

            if (Nome.Length < 5)
            {
                notification.AddError(nameof(Nome), "Tamanho minimo de nome não informado.");
            }

            if (string.IsNullOrWhiteSpace(Email))
            {
                notification.AddError(nameof(Email), "Email obrigatório.");
            }

            if (string.IsNullOrWhiteSpace(Senha))
            {
                notification.AddError(nameof(Senha), "Senha obrigatória.");
            }

            if (Senha.Length < 8)
            {
                notification.AddError(nameof(Senha), "Tamanho minimo de nome não informado.");
            }

            if (Nascimento.Equals(DateTime.MinValue))
            {
                notification.AddError(nameof(Nascimento), "Nascimento obrigatorio");
            }

            if (!BeOver18(Nascimento))
            {
                notification.AddError(nameof(Nascimento), "Usuario não possui a idade minima para cadastro");
            }

            return(notification);
        }
コード例 #31
0
        public static Try <Notification, Usuario> GetUserByLogin(string login)
        {
            var notification = new Notification(NotificationDelimiter.WebDelimiter);

            if (string.IsNullOrEmpty(login))
            {
                notification.AddError("O login informado é inválido!");
            }

            var usuario = SimulacaoDB.Where(u => u.Login == login);

            if (!usuario.Any())
            {
                notification.AddMessage(NotificationType.Warning, "Nenhum usuário encontrado com o login informado.");
            }

            if (notification.HasAnyMessage)
            {
                return(notification);
            }

            return(usuario.First());
        }