Exemplo n.º 1
0
        public async Task <Result> Handle(CreateIconCommand request, CancellationToken cancellationToken)
        {
            var id           = _identifierProvider.Generate();
            var iconToCreate = new Icon(id, request.Name, request.DataPath);

            iconToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _iconWriteRepository.CreateAsync(iconToCreate);

                result = Result.Ok(id, iconToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateIconFailure);
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <Result> Handle(CreateDamageCodeCommand request, CancellationToken cancellationToken)
        {
            Result result;
            var    id = _identifierProvider.Generate();

            var damageCodeToCreate = new DamageCode(id, request.Code, request.Name, bool.Parse(request.DamagedQuantityRequired), request.Source);

            damageCodeToCreate.Version = _versionProvider.Generate();

            try
            {
                await _damageCodeWriteRepository.CreateAsync(damageCodeToCreate);

                result = Result.Ok(id, damageCodeToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.CodeSourceConflict,
                        Target  = "code-source"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateDamageCodeFailure);
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <Result> Handle(CreateLocationCommand request, CancellationToken cancellationToken)
        {
            Result result;
            var    id = _identifierProvider.Generate();

            var locationToCreate = new Location(id, request.Source, request.Site, request.Warehouse, request.Gate, request.Row, request.Position, request.Type, bool.Parse(request.IsRack));

            locationToCreate.Version = _versionProvider.Generate();

            try
            {
                await _locationWriteRepository.CreateAsync(locationToCreate);

                result = Result.Ok(id, locationToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.SourceSiteWarehouseGateRowPositionConflict,
                        Target  = "source-site-warehouse-gate-row-position"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateLocationFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateTypePlanningCommand request, CancellationToken cancellationToken)
        {
            Result result;
            var    id = _identifierProvider.Generate();

            var typePlanningToCreate = new TypePlanning(id, request.Code, request.Name, request.Source);

            typePlanningToCreate.Version = _versionProvider.Generate();

            try
            {
                await _typePlanningWriteRepository.CreateAsync(typePlanningToCreate);

                result = Result.Ok(id, typePlanningToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.CodeSourceConflict,
                        Target  = "code-source"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateTypePlanningFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateOperatorActivityCommand request, CancellationToken cancellationToken)
        {
            dynamic jObject         = request.OperatorActivities;
            var     activitiesArray = JArray.Parse(jObject.Activities.ToString()) as JArray;
            var     activities      = _jsonService.ToObject <List <OperatorActivityDto> >(activitiesArray);
            var     result          = Result.Ok();

            try
            {
                foreach (var activityDto in activities)
                {
                    var id               = _identifierProvider.Generate();
                    var version          = _versionProvider.Generate();
                    var operatorActivity = new OperatorActivity(id);
                    _mapper.Map(activityDto, operatorActivity);
                    operatorActivity.Version = version;

                    await _operatorActivityWriteRepository.CreateAsync(operatorActivity);

                    result = Result.Ok(id, operatorActivity.Version);
                }
            }
            catch (Exception)
            {
                result = Result.Fail(CustomFailures.CreateOperatorActivityFailure);
            }

            return(result);
        }
Exemplo n.º 6
0
        public async Task <Result> Handle(CreateFlowCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var flowToCreate = new Flow(id, request.Name);

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                flowToCreate.SetDescription(request.Description);
            }
            if (!string.IsNullOrWhiteSpace(request.Image))
            {
                flowToCreate.SetImage(request.Image);
            }
            //command.BuildingBlocks.ToList().ForEach(x => flowToCreate.AddBuildingBlock(new BuildingBlock(x.Id, (BlockType)Enum.Parse(typeof(BlockType), x.BlockType, true))));
            //command.FreeActions.ToList().ForEach(x => flowToCreate.AddFreeAction(new BuildingBlock(x.Id, (BlockType)Enum.Parse(typeof(BlockType), x.BlockType, true))));
            //command.OperationalDepartments.ToList().ForEach(x => flowToCreate.AddOperationalDepartment(new FlowOperationalDepartment(x)));
            //command.Operations.ToList().ForEach(x => flowToCreate.AddOperation(new FlowOperation(x)));
            //command.ProductionSites.ToList().ForEach(x => flowToCreate.AddProductionSite(new FlowProductionSite(x)));
            //command.Sites.ToList().ForEach(x => flowToCreate.AddSite(new FlowSite(x)));
            //command.Sources.ToList().ForEach(x => flowToCreate.AddSource(new FlowSource(x)));
            //command.TransportTypes.ToList().ForEach(x => flowToCreate.AddTransportType(new FlowTransportType(x)));
            //command.TypePlannings.ToList().ForEach(x => flowToCreate.AddTypePlanning(new FlowTypePlanning(x)));
            //command.Customers.ToList().ForEach(x => flowToCreate.AddCustomer(new FlowCustomer(x)));

            flowToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _flowWriteRepository.CreateAsync(flowToCreate);

                result = Result.Ok(id, flowToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateFlowFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateOperationCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var operationToCreate = new Operation(id, request.Name);

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                operationToCreate.SetDescription(request.Description);
            }
            if (request.Icon != null)
            {
                var coloredIcon = new ColoredIcon(request.Icon.IconId, request.Icon.FillColor);
                operationToCreate.SetIcon(coloredIcon);
            }
            foreach (var tag in request.Tags)
            {
                operationToCreate.AddTag(new Tag(tag));
            }

            operationToCreate.Version = _versionProvider.Generate();


            Result result;

            try
            {
                await _operationWriteRepository.CreateAsync(operationToCreate);

                result = Result.Ok(id, operationToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateOperationFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateInputCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var inputToCreate = new Input(id, request.Name, request.Description, request.Icon, request.Instruction);

            foreach (var image in request.Images)
            {
                inputToCreate.AddImage(new Image(image.Name, "some image url"));
            }
            foreach (var video in request.Videos)
            {
                inputToCreate.AddVideo(new Video(video.Name, "some image url"));
            }
            foreach (var tag in request.Tags)
            {
                inputToCreate.AddTag(new Tag(tag));
            }

            inputToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _inputWriteRepository.CreateAsync(inputToCreate);

                result = Result.Ok(id, inputToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateInstructionFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateTeamCommand command, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var teamToCreate = new Team(TeamId.With(id), new Name(command.Name));

            teamToCreate.SetImage(command.Image);
            teamToCreate.SetDescription((Description)command.Description);

            if (Guid.TryParse(command.Layout, out Guid layoutId) && layoutId != default(Guid))
            {
                var layout = new Layout(layoutId);
                teamToCreate.SetLayout(layout);
            }

            teamToCreate.SetVersion(_versionProvider.Generate());

            Result result;

            try
            {
                await _teamWriteRepository.CreateAsync(teamToCreate);

                return(Result.Ok(id, teamToCreate.Version));
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.ConflictTeam,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateTeamFailure);
            }

            return(result);
        }
Exemplo n.º 10
0
        public async Task <Result> Handle(CreatePlatoOrderCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var platoOrderId = _identifierProvider.Generate();
                await _platoOrderWriteRepository.CreateAsync(new PlatoOrder(platoOrderId, request.PlatoOrder));


                var platoOrderOverview = _platoOrderProvider.GetPlatoOrderOverview(request.PlatoOrder);

                //_platoOrderChecker.Check(platoOrderOverview);

                var order = _domainConverter.ToOrder(platoOrderOverview);

                Operational operational = new Operational(Status.Open);

                var workOrder = new WorkOrder.Builder()
                                .WithId(Guid.NewGuid())
                                .WithIsEditable(false)
                                .WithCreatedOn(new CreatedOn(DateTime.UtcNow))
                                .WithUserCreated("Plato")
                                .WithOrder(order)
                                .WithOperational(operational)
                                .Build();

                workOrder.Version = _versionProvider.Generate();
                await _workOrderWriteRepository.CreateAsync(workOrder);

                result = Result.Ok(workOrder.Id, workOrder.Version);
            }
            catch (PlatoOrderOverviewCheckException ex)
            {
                _logAs.Error(CustomFailures.CreatePlatoOrderFailure, ex);
                result = Result.Fail(CustomFailures.CreatePlatoOrderFailure);
            }
            catch (Exception ex)
            {
                _logAs.Error(CustomFailures.CreatePlatoOrderFailure, ex);
                result = Result.Fail(CustomFailures.CreatePlatoOrderFailure);
            }
            return(result);
        }
        public async Task <Result> Handle(CreateLayoutCommand request, CancellationToken cancellationToken)
        {
            var id             = _identifierProvider.Generate();
            var layoutToCreate = new Layout(id, request.Name);

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                layoutToCreate.SetDescription(request.Description);
            }
            if (!string.IsNullOrWhiteSpace(request.Image))
            {
                layoutToCreate.SetImage(request.Image);
            }
            layoutToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _layoutWriteRepository.CreateAsync(layoutToCreate);

                result = Result.Ok(id, layoutToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateLayoutFailure);
            }

            return(result);
        }
Exemplo n.º 12
0
        public async Task <Result> Handle(CreateCommand command, CancellationToken cancellationToken)
        {
            var id             = _identifierProvider.Generate();
            var login          = new Login(command.Login);
            var passwordHashed = _passwordProvider.Hash(command.Password);

            var firstName    = new FirstName(command.FirstName);
            var lastName     = new LastName(command.LastName);
            var fullName     = new FullName(firstName, lastName);
            var userToCreate = new User(id, login, passwordHashed, fullName);

            userToCreate.Version = _versionProvider.Generate();
            Result result;

            try
            {
                await _userRepository.Create(userToCreate);

                result = Result.Ok(id, userToCreate.Version);
                await _publishIntegrationEventsService.PublishUserCreated(id, command.Login, command.FirstName, command.LastName);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "login"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateUserFailure);
            }

            return(result);
        }
Exemplo n.º 13
0
        public async Task <Result> Handle(CreateSourceCommand request, CancellationToken cancellationToken)
        {
            var id             = _identifierProvider.Generate();
            var sourceToCreate = new Source(id, request.Name, request.Description);

            foreach (var sourceBusinessUnit in request.SourceBusinessUnits)
            {
                sourceToCreate.AddSourceBusinessUnit(new SourceBusinessUnit(sourceBusinessUnit));
            }
            sourceToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _sourceWriteRepository.CreateAsync(sourceToCreate);

                result = Result.Ok(id, sourceToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateSourceFailure);
            }

            return(result);
        }
Exemplo n.º 14
0
        public async Task <Result> Handle(CreateRemarkCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var remarkToCreate = new Remark(id, request.Name, request.NameOnApplication, request.Description, new RemarkIcon(request.Icon));

            request.Tags.ToList().ForEach(x => remarkToCreate.AddTag(new Tag(x)));
            request.DefaultRemarks.ToList().ForEach(x => remarkToCreate.AddDefaultRemark(new DefaultRemark(x)));

            remarkToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _remarkWriteRepository.CreateAsync(remarkToCreate);

                result = Result.Ok(id, remarkToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateRemarkFailure);
            }

            return(result);
        }
Exemplo n.º 15
0
        public async Task <Result> Handle(UpdateValidationCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var validation = await _validationReadRepository.GetAsync(request.Id);

                if (validation.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                var tags = new List <Tag>();
                foreach (var tag in request.Tags)
                {
                    tags.Add(new Tag(tag));
                }
                var images = new List <Image>();
                foreach (var image in request.Images)
                {
                    images.Add(new Image(image.Name, "some image url"));
                }
                var videos = new List <Video>();
                foreach (var video in request.Videos)
                {
                    videos.Add(new Video(video.Name, "some image url"));
                }

                var icon = new BuildingBlockIcon(request.Icon.Id);


                var updatedValidation = new Validation(request.Id,
                                                       request.Name,
                                                       request.NameOnApplication,
                                                       request.Description,
                                                       request.Instruction,
                                                       icon);

                foreach (var tag in tags)
                {
                    updatedValidation.AddTag(tag);
                }
                foreach (var image in images)
                {
                    updatedValidation.AddImage(image);
                }
                foreach (var video in videos)
                {
                    updatedValidation.AddVideo(video);
                }

                updatedValidation.Version = _versionProvider.Generate();


                await _validationWriteRepository.UpdateAsync(updatedValidation);

                result = Result.Ok(updatedValidation.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Validation"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateValidationFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(UpdateInstructionCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var instruction = await _instructionReadRepository.GetAsync(request.Id);

                if (instruction.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                var updatedInstruction = new Instruction(request.Id, request.Name, request.Description, request.Icon, request.Content, request.Image, request.Video);
                foreach (var tag in request.Tags)
                {
                    updatedInstruction.AddTag(new Tag(tag));
                }

                updatedInstruction.Version = _versionProvider.Generate();
                await _instructionWriteRepository.UpdateAsync(updatedInstruction);

                result = Result.Ok(updatedInstruction.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Instruction"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateInstructionFailure);
            }

            return(result);
        }
Exemplo n.º 17
0
        public async Task <Result> Handle(UpdateTeamCommand command, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var team = await _teamReadRepository.GetAsync(command.Id);

                if (team.Version != command.Version)
                {
                    throw new CommandVersionException();
                }

                team.ChangeName(new Name(command.Name));
                team.SetImage(command.Image);
                team.SetDescription((Description)command.Description);

                if (Guid.TryParse(command.Layout, out Guid layoutId) && layoutId != default(Guid))
                {
                    var layout = new Layout(layoutId);
                    team.SetLayout(layout);
                }

                team.SetFilterContent(command.FilterContent);
                team.ChangeDriverWait(DriverWait.Parse(command.DriverWait));

                team.ClearMembers();
                foreach (var operatorId in command.Members)
                {
                    var member = new Member(operatorId);
                    team.AddMember(member);
                }

                team.SetVersion(_versionProvider.Generate());

                await _teamWriteRepository.UpdateAsync(team);

                result = Result.Ok(team.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = HandlerFailures.TeamNotFound,
                        Target  = "id"
                    }
                });
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                });
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.ConflictTeam,
                        Target  = "name"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateTeamFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(UpdateSourceCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var source = await _sourceReadRepository.GetAsync(request.Id);

                if (source.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                if (request.Name.HasValue)
                {
                    source.ChangeName(request.Name.Value);
                }
                if (request.Description.HasValue)
                {
                    source.ChangeDescription(request.Description.Value);
                }
                if (request.SourceBusinessUnits.HasValue)
                {
                    var sourceBusinessUnits = request.SourceBusinessUnits.Value ?? new List <string>();
                    source.ClearSourceBusinessUnits();
                    foreach (var sourceBusinessUnit in sourceBusinessUnits)
                    {
                        source.AddSourceBusinessUnit(new SourceBusinessUnit(sourceBusinessUnit));
                    }
                }

                source.Version = _versionProvider.Generate();
                await _sourceWriteRepository.UpdateAsync(source);

                result = Result.Ok(source.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Source"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateSourceFailure);
            }

            return(result);
        }
Exemplo n.º 19
0
        public async Task <Result> Handle(UpdateIconCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var icon = await _iconReadRepository.GetAsync(request.Id);

                if (icon.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                if (request.Name.HasValue)
                {
                    icon.ChangeName(request.Name.Value);
                }
                if (request.DataPath.HasValue)
                {
                    icon.ChangeDataPath(request.DataPath.Value);
                }

                icon.Version = _versionProvider.Generate();
                await _iconWriteRepository.UpdateAsync(icon);

                result = Result.Ok(icon.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Icon"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateIconFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(UpdateLayoutCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var layout = await _layoutReadRepository.GetAsync(request.Id);

                if (layout.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                if (request.Name.HasValue)
                {
                    layout.ChangeName(request.Name.Value);
                }
                if (request.Description.HasValue)
                {
                    layout.SetDescription(request.Description.Value);
                }
                if (request.Image.HasValue)
                {
                    layout.SetImage(request.Image.Value);
                }
                if (request.Diagram.HasValue)
                {
                    layout.SetDiagram(request.Diagram.Value);
                }
                layout.Version = _versionProvider.Generate();
                await _layoutWriteRepository.UpdateAsync(layout);

                result = Result.Ok(layout.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Layout"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateLayoutFailure);
            }

            return(result);
        }
Exemplo n.º 21
0
        public async Task <Result> Handle(UpdateWorkOrderCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var workOrderToUpdate = await _workOrderReadRepository.GetAsync(request.Id);

                if (workOrderToUpdate.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                if (request.Operant.HasValue)
                {
                    var operant = request.Operant.Value;
                    workOrderToUpdate.Operational.SetOperant(operant);
                }
                if (request.Status.HasValue)
                {
                    var status = Status.Parse(request.Status.Value);
                    workOrderToUpdate.Operational.ChangeStatus(status);
                }
                if (request.StartedOn.HasValue)
                {
                    var startedOnValue = _dateTimeProvider.Parse(request.StartedOn.Value);
                    if (startedOnValue.HasValue)
                    {
                        var startedOn = new DateOn(startedOnValue.Value);
                        workOrderToUpdate.Operational.SetStartedOn(startedOn);
                    }
                }
                if (request.HandledUnits.HasValue)
                {
                    workOrderToUpdate.Operational.ClearHandledUnits();
                    foreach (var handledUnitDto in request.HandledUnits.Value)
                    {
                        var id                = new Guid(handledUnitDto.Id);
                        var operantId         = new Guid(handledUnitDto.OperantId);
                        var operantLogin      = new Login(handledUnitDto.OperantLogin);
                        var sourceUnitId      = new Guid(handledUnitDto.SourceUnitId);
                        var locationWarehouse = handledUnitDto.Warehouse;
                        var locationGate      = handledUnitDto.Gate;
                        var locationRow       = handledUnitDto.Row;
                        var locationPosition  = handledUnitDto.Position;
                        var units             = new Units(int.Parse(handledUnitDto.Units));
                        var isPartial         = bool.Parse(handledUnitDto.IsPartial);
                        var isMixed           = bool.Parse(handledUnitDto.IsMixed);
                        var quantity          = new Quantity(int.Parse(handledUnitDto.Quantity));
                        var weightNet         = new Weight(float.Parse(handledUnitDto.WeightNet));
                        var weightGross       = new Weight(float.Parse(handledUnitDto.WeightGross));
                        var palletNumber      = handledUnitDto.PalletNumber;
                        var ssccNumber        = handledUnitDto.SsccNumber;

                        var operant    = new Operant(operantId, operantLogin);
                        var sourceUnit = workOrderToUpdate.Order.Units.First(x => x.Id == sourceUnitId);
                        var handledOn  = new HandledOn(_dateTimeProvider.Parse(handledUnitDto.HandledOn).Value);
                        var location   = new Location(
                            new Warehouse(new Label(locationWarehouse)),
                            new Gate(new Label(locationGate)),
                            new Row(new Label(locationRow)),
                            new Position(new Label(locationPosition))
                            );
                        var type = sourceUnit.Type;


                        var goodDtos = handledUnitDto.Products;
                        var goods    = new List <Good>();
                        foreach (var goodDto in goodDtos)
                        {
                            var goodId = new Guid(goodDto.Id);

                            var good = new Good(goodId);

                            good.SetConfiguration(
                                new Configuration(
                                    code: goodDto.CongfigurationCode,
                                    description: goodDto.CongfigurationDescription,
                                    quantity: goodDto.CongfigurationQuantity,
                                    unitType: goodDto.CongfigurationUnitType,
                                    netPerUnit: goodDto.CongfigurationNetPerUnit,
                                    netPerUnitAlwaysDifferent: goodDto.CongfigurationNetPerUnitAlwaysDifferent,
                                    grossPerUnit: goodDto.CongfigurationGrossPerUnit
                                    )
                                );
                            good.SetCode(goodDto.Code);
                            good.SetCustomer(goodDto.Customer);
                            good.SetArrival(goodDto.Arrival);
                            good.SetArticle(goodDto.Article);
                            good.SetArticlePackagingCode(goodDto.ArticlePackagingCode);
                            good.SetName(goodDto.Code);
                            good.SetGtin(goodDto.Gtin);
                            good.SetProductType(goodDto.ProductType);
                            good.SetMaterialType(goodDto.MaterialType);
                            good.SetColor(goodDto.Color);
                            good.SetShape(goodDto.Shape);
                            good.SetLotbatch(goodDto.Lotbatch);
                            good.SetLotbatch2(goodDto.Lotbatch2);
                            good.SetClientReference(goodDto.ClientReference);
                            good.SetClientReference2(null);
                            good.SetBestBeforeDate(_dateTimeProvider.Parse(goodDto.BestBeforeDate).HasValue ? new DateOn(_dateTimeProvider.Parse(goodDto.BestBeforeDate).Value) : null);
                            good.SetDateFifo(_dateTimeProvider.Parse(goodDto.DateFifo).HasValue ? new DateOn(_dateTimeProvider.Parse(goodDto.DateFifo).Value) : null);
                            good.SetCustomsDocument(goodDto.CustomsDocument);
                            good.SetStorageStatus(goodDto.StorageStatus);
                            good.SetStackheight(goodDto.Stackheight);
                            good.SetLength(goodDto.Length);
                            good.SetWidth(goodDto.Width);
                            good.SetHeight(goodDto.Height);
                            good.SetOriginalContainer(goodDto.OriginalContainer);
                            good.SetQuantity(new Quantity(_typeConverterProvider.ToInt(goodDto.Quantity)));
                            good.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(goodDto.WeightNet)));
                            good.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(goodDto.WeightGross)));

                            goods.Add(good);
                        }

                        var handledUnit = new HandledUnit(id, sourceUnit);
                        handledUnit.SetOperant(operant);
                        handledUnit.SetHandledOn(handledOn);
                        handledUnit.SetLocation(location);
                        handledUnit.SetType(type);

                        handledUnit.SetUnits(units);
                        handledUnit.SetIsPartial(isPartial);
                        handledUnit.SetIsMixed(isMixed);
                        handledUnit.SetQuantity(quantity);
                        handledUnit.SetWeightNet(weightNet);
                        handledUnit.SetWeightGross(weightGross);

                        handledUnit.SetPalletNumber(palletNumber);
                        handledUnit.SetSsccNumber(ssccNumber);

                        foreach (var good in goods)
                        {
                            handledUnit.AddGood(good);
                        }

                        workOrderToUpdate.Operational.AddHandledUnit(handledUnit);
                    }
                }
                if (request.Remarks.HasValue)
                {
                    workOrderToUpdate.Operational.ClearRemarks();
                    foreach (var remarkDto in request.Remarks.Value)
                    {
                        var operantId    = new Guid(remarkDto.OperantId);
                        var operantLogin = remarkDto.Operant;
                        var operant      = new Operant(operantId, new Login(operantLogin));
                        var createdOn    = new CreatedOn(_dateTimeProvider.Parse(remarkDto.CreatedOn).Value);
                        var text         = remarkDto.Text;
                        var remark       = new Remark(operant, createdOn, text);
                        workOrderToUpdate.Operational.AddRemark(remark);
                    }
                }
                if (request.Pictures.HasValue)
                {
                    workOrderToUpdate.Operational.ClearPictures();
                    foreach (var pictureDto in request.Pictures.Value)
                    {
                        var operantId    = new Guid(pictureDto.OperantId);
                        var operantLogin = pictureDto.Operant;
                        var operant      = new Operant(operantId, new Login(operantLogin));
                        var createdOn    = new CreatedOn(_dateTimeProvider.Parse(pictureDto.CreatedOn).Value);
                        var name         = pictureDto.Name;
                        var picture      = new Picture(operant, createdOn, name);
                        workOrderToUpdate.Operational.AddPicture(picture);
                    }
                }
                if (request.Inputs.HasValue)
                {
                    workOrderToUpdate.Operational.ClearInputs();
                    foreach (var inputDto in request.Inputs.Value)
                    {
                        var operantId    = new Guid(inputDto.OperantId);
                        var operantLogin = inputDto.Operant;
                        var operant      = new Operant(operantId, new Login(operantLogin));
                        var createdOn    = new CreatedOn(_dateTimeProvider.Parse(inputDto.CreatedOn).Value);
                        var value        = inputDto.Value;
                        var property     = inputDto.Property;
                        var input        = new Input(operant, createdOn, value, property);
                        workOrderToUpdate.Operational.AddInput(input);
                    }
                }


                workOrderToUpdate.Version = _versionProvider.Generate();

                await _workOrderWriteRepository.UpdateAsync(workOrderToUpdate);

                result = Result.Ok(workOrderToUpdate.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "WorkOrder"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "workOrder"
                    }
                }
                                     );
            }
            catch (Exception ex)
            {
                _logAs.Error(CustomFailures.UpdateWorkOrderFailure, ex);
                result = Result.Fail(CustomFailures.UpdateWorkOrderFailure);
            }
            return(result);
        }
Exemplo n.º 22
0
        public async Task <Result> Handle(UpdateOperationCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var operation = await _operationReadRepository.GetAsync(request.Id);

                if (operation.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                //var coloredIcon = new ColoredIcon(command.Icon.IconId, command.Icon.FillColor);

                if (request.Name.HasValue)
                {
                    operation.ChangeName(request.Name.Value);
                }
                if (request.Description.HasValue)
                {
                    operation.SetDescription(request.Description.Value);
                }

                if (request.Tags.HasValue)
                {
                    var tags = request.Tags.Value ?? new List <string>();
                    operation.ClearTags();
                    foreach (var tag in tags)
                    {
                        operation.AddTag(new Tag(tag));
                    }
                }

                operation.Version = _versionProvider.Generate();
                await _operationWriteRepository.UpdateAsync(operation);

                result = Result.Ok(operation.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Operation"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateOperationFailure);
            }

            return(result);
        }
Exemplo n.º 23
0
        public async Task <Result> Handle(CreateWorkOrderCommand request, CancellationToken cancellationToken)
        {
            //var order = new Order.Builder()
            //                     .WithSite(request.Order.Site)
            //                     .WithCustomer(request.Order.Customer)
            //                     .WithOperationalDepartment(request.Order.OperationalDepartment)
            //                     .WithLicensePlateTrailer(request.Order.LicensePlateTrailer)
            //                     .WithLicensePlateTruck(request.Order.LicensePlateTruck)
            //                     .WithContainer(request.Order.Container)
            //                     .WithContainerLocation(request.Order.ContainerLocation)
            //                     .WithDockingZone(request.Order.DockingZone)
            //                     .Build();


            Result result;

            try
            {
                var order = new Order()
                {
                    Origin = new Origin()
                    {
                        Source = "ECC"
                    },
                    Number = null,

                    Customer = new Customer()
                    {
                        Code           = null,
                        ProductionSite = null,
                        Reference1     = null,
                        Reference2     = null,
                        Reference3     = null,
                        Reference4     = null,
                        Reference5     = null
                    },
                    Customs = new Customs()
                    {
                        CertificateOfOrigin = null,
                        Document            = new Document()
                        {
                            Name   = null,
                            Number = null,
                            Office = null,
                            Date   = null
                        }
                    },
                    Transport = new Transport()
                    {
                        Kind   = null,
                        Type   = null,
                        Driver = new Driver()
                        {
                            Name = null,
                            Wait = Wait.Undefined
                        },
                        Delivery = new Delivery()
                        {
                            Place = null
                        },
                        Loading = new Loading()
                        {
                            Place     = null,
                            Reference = null,
                        },
                        Truck = new Truck()
                        {
                            LicensePlateTruck   = null,
                            LicensePlateTrailer = null,
                        },
                        Container = new Container()
                        {
                            Number        = null,
                            Location      = null,
                            StackLocation = null
                        },
                        Railcar = new Railcar()
                        {
                            Number = null
                        },
                        Ard = new Ard()
                        {
                            Reference1  = null,
                            Reference2  = null,
                            Reference3  = null,
                            Reference4  = null,
                            Reference5  = null,
                            Reference6  = null,
                            Reference7  = null,
                            Reference8  = null,
                            Reference9  = null,
                            Reference10 = null
                        },
                        Arrival = new Arrival()
                        {
                            Expected = null,
                            Arrived  = null,
                            Latest   = null
                        },
                        BillOfLading = new BillOfLading()
                        {
                            Number      = null,
                            WeightNet   = null,
                            WeightGross = null
                        },
                        Carrier = new Carrier()
                        {
                            Arrived = null,
                            Booked  = null
                        },
                        Weighbridge = new Weighbridge()
                        {
                            Net   = null,
                            Gross = null
                        },
                        Seal = new Seal()
                        {
                            Seal1 = null,
                            Seal2 = null,
                            Seal3 = null
                        },
                        Adr = null
                    },
                    Operation = new Operation()
                    {
                        Dispatch = new Dispatch()
                        {
                            Priority = null,
                            To       = null,
                            Comment  = null
                        },

                        Type                  = OperationType.Inbound,
                        Name                  = request.Operation,
                        UnitPlanning          = null,
                        TypePlanning          = null,
                        Site                  = request.Site,
                        Zone                  = null,
                        OperationalDepartment = request.Department,
                        DockingZone           = null,
                        LoadingDock           = null,
                        ProductOverview       = null,
                        LotbatchOverview      = null
                    }
                };
                var operational = new Operational(Status.Open);

                var workOrder = new WorkOrder.Builder()
                                .WithId(_identifierProvider.Generate())
                                .WithIsEditable(true)
                                .WithCreatedOn(new CreatedOn(DateTime.UtcNow))
                                .WithUserCreated(request.UserCreated)
                                .WithOrder(order)
                                .WithOperational(operational)
                                .Build();


                workOrder.Version = _versionProvider.Generate();

                await _workOrderWriteRepository.CreateAsync(workOrder);

                result = Result.Ok(workOrder.Id, workOrder.Version);
            }
            catch (UniqueKeyDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "workOrder"
                    }
                });
            }
            catch (Exception ex)
            {
                _logAs.Error(CustomFailures.CreateWorkOrderFailure, ex);
                result = Result.Fail(CustomFailures.CreateWorkOrderFailure);
            }
            return(result);
        }
        public async Task <Result> Handle(UpdateFlowCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var flow = await _flowReadRepository.GetAsync(request.Id);

                if (flow.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                if (request.Name.HasValue)
                {
                    flow.ChangeName(request.Name.Value);
                }
                if (request.Description.HasValue)
                {
                    flow.SetDescription(request.Description.Value);
                }
                if (request.Image.HasValue)
                {
                    flow.SetImage(request.Image.Value);
                }
                if (request.Diagram.HasValue)
                {
                    flow.SetDiagram(request.Diagram.Value);
                }
                if (request.FilterContent.HasValue)
                {
                    flow.SetFilterContent(request.FilterContent.Value);
                    var filter = _jsonService.Deserialize <FlowFilter>(request.FilterContent.Value.ToString());

                    filter.Sources = (filter.Sources.IsEnumerableNullOrEmpty()) ? new List <FlowSource> {
                        new FlowSource("x")
                    } : new List <FlowSource>(filter.Sources);
                    filter.Operations = (filter.Operations.IsEnumerableNullOrEmpty()) ? new List <FlowOperation> {
                        new FlowOperation("x")
                    } : new List <FlowOperation>(filter.Operations);
                    filter.Sites = (filter.Sites.IsEnumerableNullOrEmpty()) ? new List <FlowSite> {
                        new FlowSite("x")
                    } : new List <FlowSite>(filter.Sites);
                    filter.OperationalDepartments = (filter.OperationalDepartments.IsEnumerableNullOrEmpty()) ? new List <FlowOperationalDepartment> {
                        new FlowOperationalDepartment("x")
                    } : new List <FlowOperationalDepartment>(filter.OperationalDepartments);
                    filter.TypePlannings = (filter.TypePlannings.IsEnumerableNullOrEmpty()) ? new List <FlowTypePlanning> {
                        new FlowTypePlanning("x")
                    } : new List <FlowTypePlanning>(filter.TypePlannings);
                    filter.Customers = (filter.Customers.IsEnumerableNullOrEmpty()) ? new List <FlowCustomer> {
                        new FlowCustomer("x")
                    } : new List <FlowCustomer>(filter.Customers);
                    filter.ProductionSites = (filter.ProductionSites.IsEnumerableNullOrEmpty()) ? new List <FlowProductionSite> {
                        new FlowProductionSite("x")
                    } : new List <FlowProductionSite>(filter.ProductionSites);
                    filter.TransportTypes = (filter.TransportTypes.IsEnumerableNullOrEmpty()) ? new List <FlowTransportType> {
                        new FlowTransportType("x")
                    } : new List <FlowTransportType>(filter.TransportTypes);
                    filter.DriverWait = (filter.DriverWait == null) ? "x" : filter.DriverWait;

                    flow.SetFilter(filter);
                }

                flow.Version = _versionProvider.Generate();
                await _flowWriteRepository.UpdateAsync(flow);

                result = Result.Ok(flow.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Flow"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateFlowFailure);
            }

            return(result);
        }
        public async Task <Result> Handle(CreateValidationCommand request, CancellationToken cancellationToken)
        {
            var id   = _identifierProvider.Generate();
            var tags = new List <Tag>();

            foreach (var tag in request.Tags)
            {
                tags.Add(new Tag(tag));
            }
            var images = new List <Image>();

            foreach (var image in request.Images)
            {
                images.Add(new Image(image.Name, "some image url"));
            }
            var videos = new List <Video>();

            foreach (var video in request.Videos)
            {
                videos.Add(new Video(video.Name, "some image url"));
            }

            var icon = new BuildingBlockIcon(request.Icon.Id);


            var validationBlockToCreate = new Validation(id,
                                                         request.Name,
                                                         request.NameOnApplication,
                                                         request.Description,
                                                         request.Instruction,
                                                         icon);

            foreach (var tag in tags)
            {
                validationBlockToCreate.AddTag(tag);
            }
            foreach (var image in images)
            {
                validationBlockToCreate.AddImage(image);
            }
            foreach (var video in videos)
            {
                validationBlockToCreate.AddVideo(video);
            }

            validationBlockToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _validationWriteRepository.CreateAsync(validationBlockToCreate);

                result = Result.Ok(id, validationBlockToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateValidationFailure);
            }

            return(result);
        }
Exemplo n.º 26
0
        public async Task <Result> Handle(UpdateRemarkCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var icon = await _remarkReadRepository.GetAsync(request.Id);

                if (icon.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                var updatedRemark = new Remark(request.Id, request.Name, request.NameOnApplication, request.Description, new RemarkIcon(request.Icon));
                request.Tags.ToList().ForEach(x => updatedRemark.AddTag(new Tag(x)));
                request.DefaultRemarks.ToList().ForEach(x => updatedRemark.AddDefaultRemark(new DefaultRemark(x)));

                updatedRemark.Version = _versionProvider.Generate();
                await _remarkWriteRepository.UpdateAsync(updatedRemark);

                result = Result.Ok(updatedRemark.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Remark"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateRemarkFailure);
            }

            return(result);
        }
Exemplo n.º 27
0
        public async Task <Result> Handle(UpdateCommand command, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var user = await _userFinder.Get(command.Id);

                if (user.Version != command.Version)
                {
                    throw new CommandVersionException();
                }
                if (command.Login.HasValue)
                {
                    var updatedLogin = command.Login.Value;
                    user.ChangeLogin(new Login(updatedLogin));
                }
                if (command.Password.HasValue)
                {
                    var passwordHashed = _passwordProvider.Hash(command.Password.Value);
                    user.ChangePassword(passwordHashed);
                }
                if (command.FirstName.HasValue)
                {
                    user.FullName.ChangeFirstName(command.FirstName.Value);
                }
                if (command.LastName.HasValue)
                {
                    user.FullName.ChangeLastName(command.LastName.Value);
                }
                user.Version = _versionProvider.Generate();
                await _userRepository.Update(user);

                result = Result.Ok(user.Version);
                await _publishIntegrationEventsService.PublishUserUpdated(user.Id, user.Login.Value, user.FullName.FirstName.Value, user.FullName.LastName.Value);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = HandlerFailures.NotFound,
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (CommandVersionException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "login"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.UpdateUserFailure);
            }

            return(result);
        }