コード例 #1
0
        public Response <int> AddOrUpdate(AddPersonCommand addPersonCommand)
        {
            try
            {
                if (addPersonCommand == null || !addPersonCommand.IsValid)
                {
                    return(new Response <int> {
                        Success = false, Message = "Invalid Person"
                    });
                }
                var person = new Person(addPersonCommand.Id, addPersonCommand.FirstName, addPersonCommand.LastName, addPersonCommand.StreetName, addPersonCommand.HouseNumber, addPersonCommand.PostalCode,
                                        addPersonCommand.ApartmentNumber, addPersonCommand.PhoneNumber, addPersonCommand.DateOfBirth, addPersonCommand.Town);

                var response = _personRepository.AddorUpdate(person);
                return(response.Success ?
                       new Response <int> {
                    Success = true, Data = response.Data
                } : new Response <int> {
                    Success = false, Message = response.Message
                });
            }
            catch (Exception ex)
            {
                return(new Response <int> {
                    Success = false, Message = ex.GetBaseException().Message
                });
            }
        }
コード例 #2
0
        public void AddPerson([FromBody] AddPersonRequest request)
        {
            _logger.LogInformation("Adding a person");
            var command = AddPersonCommand.ConvertFromRequest(request);

            _peopleCommandHandler.Handle(command);
        }
コード例 #3
0
        public async void HandleAddPersonCommand_WithUser_ShouldReturnUserAlreadyExists()
        {
            //Arrange

            #region build person
            string document    = "75115775122";
            string name        = "Andre Santarosa";
            string phoneNumber = "19999990000";
            string email       = "*****@*****.**";

            Person person = null;
            person = new Person(Guid.NewGuid(), document, name, email);
            List <PersonPhone> phones = new List <PersonPhone>();
            phones.Add(new PersonPhone(Guid.NewGuid(), phoneNumber, person));
            #endregion

            Mocker.GetMock <IPersonRepository>()
            .Setup(u => u.GetByDocument(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(() => Task.FromResult(person));

            var sut           = Mocker.CreateInstance <AddPersonCommandHandler>();
            var personCommand = new AddPersonCommand(document, name, email, new List <string>()
            {
                phoneNumber
            });

            //Act
            await sut.Handle(personCommand, new System.Threading.CancellationToken());

            //Assert
            DomainNotifications.GetAll().Should().NotBeEmpty().And.Contain(x => x == Domain.Resources.Messages.Person_PersonWithDocumentExists)
            .And.HaveCount(1);
            Mocker.GetMock <IPersonRepository>().Verify(x => x.GetByDocument(It.IsAny <string>(), It.IsAny <bool>()), Times.Once());
            Mocker.GetMock <IPersonRepository>().Verify(x => x.AddPerson(It.IsAny <Person>()), Times.Never());
        }
コード例 #4
0
        public async Task <IActionResult> Post()
        {
            AddPersonCommand command = new AddPersonCommand(10, "Stiven");
            var result = await mediator.Send(command);

            return(Ok(result));
        }
コード例 #5
0
ファイル: PersonController.cs プロジェクト: ddangelorb/cg4u
        //[Authorize(Policy = "Person.Add")]
        public async Task <IActionResult> AddPersonAsync([FromBody] PersonViewModel viewModel)
        {
            if (!IsModelStateValid())
            {
                return(Response());
            }

            var domain      = Mapper.Map <Person>(viewModel);
            var personIdApi = await _personAdapter.CreatePersonAsync(domain);

            if (personIdApi == null)
            {
                NotifyError("", "Could not create Person on Adapter");
                return(Response());
            }

            var userLoggedInDB = await GetUserDbByIdentityAsync(HttpContext);

            if (userLoggedInDB == null)
            {
                return(Response());
            }
            var userLoggedIn = Mapper.Map <UserViewModel, User>(userLoggedInDB);

            var domainModel = Mapper.Map <PersonModel>(viewModel);

            domainModel.IdApi = new Guid(personIdApi);

            var cmd = new AddPersonCommand(userLoggedIn, domainModel);
            await _mediator.SendCommand(cmd);

            return(Response(cmd));
        }
コード例 #6
0
        public int AddPerson(AddPersonCommand person)
        {
            var index = people.ToList().OrderByDescending(x => x.Id).First().Id + 1;

            people.Add(new Person {
                Id = index, Name = person.Name, Age = person.Age
            });
            return(index);
        }
コード例 #7
0
ファイル: AddPersonViewModel.cs プロジェクト: alam97/TP19
 public AddPersonViewModel(Store store)
 {
     this.store = store;
     person     = new Person()
     {
         FirstName = "FirstName",
         LastName  = "LastName",
         Id        = 10
     };
     AddPersonCommand = new AddPersonCommand(this);
 }
コード例 #8
0
        public async Task <IActionResult> Add([FromBody] PersonModel model)
        {
            var user = await _userManagerWrapper.FindByNameAsync(User.Identity.Name);

            model.UserId = user.Id;
            var addPersonCommand = new AddPersonCommand {
                Person = model
            };
            await _endpointInstance.Send("LifeManager.People", addPersonCommand).ConfigureAwait(false);

            return(Ok());
        }
コード例 #9
0
        public void Add(Person entity)
        {
            //I can use automapper here !
            var addressCommand = new AddressCommand(entity.Address.PostalCode, entity.Address.City, entity.Address.State,
                                                    entity.Address.Country, entity.Address.NeighborHood, entity.Address.Street,
                                                    entity.Address.Complement, entity.Address.Number);

            var addPersonCommand = new AddPersonCommand(entity.Name, addressCommand);


            _mediator.SendCommand(addPersonCommand);
        }
コード例 #10
0
        public MainWindowViewModel(Action listRefresh)
        {
            _ctx = new DbModelContainer();
            var personalEFRepository = new PersonalEFRepository(_ctx);
            var postsEFRepository    = new PostsEFRepository(_ctx);

            Personal            = new LocalPersonalCollection();
            LoadPersonalCommand = new LoadPersonalCommand(personalEFRepository, Personal);
            AddEngineerCommand  = new AddPersonCommand(new PersonFactoryWPF(new AddEngineerDialogFactory(postsEFRepository)), personalEFRepository, Personal);
            AddWorkerCommand    = new AddPersonCommand(new PersonFactoryWPF(new AddWorkerDialogFactory(postsEFRepository)), personalEFRepository, Personal);
            EditPersonCommand   = new EditPersonCommand(personalEFRepository, Personal, postsEFRepository);
            LoadPersonalCommand.Execute();
        }
コード例 #11
0
ファイル: MainWindowVM.cs プロジェクト: aeroslave/Chat
        /// <summary>
        /// Конструктор.
        /// </summary>
        public MainWindowVM()
        {
            MessageList = new ObservableCollection <string>();
            ActiveUsers = new ObservableCollection <string>();

            GetConnectionCommand = new GetConnectionCommand();
            DisconnectionCommand = new DisconnectionCommand();
            SendMessageCommand   = new SendMessageCommand();
            AddPersonCommand     = new AddPersonCommand();
            CheckPersonCommand   = new CheckPersonCommand();

            GetPersons();
        }
コード例 #12
0
        public HttpResponseMessage PersonAdd(JObject jsonData)
        {
            dynamic json = jsonData;

            try
            {
                var Person = new AddPersonCommand();
                //{
                Person.IntegrationCode       = Guid.NewGuid();
                Person.Name                  = json.Name.ToString();
                Person.FantasyName           = json.FantasyName.ToString();
                Person.NameFromSecurityCheck = json.NameFromSecurityCheck.ToString();
                Person.SecuritySourceId      = string.IsNullOrEmpty((json.SecuritySourceId).Value) ? null : int.Parse(json.SecuritySourceId.ToString());
                Person.IsSafe                = string.IsNullOrEmpty((json.IsSafe).Value) ? null : Boolean.Parse((json.IsSafe).Value);
                Person.FriendlyNameURL       = json.FriendlyNameURL.ToString();
                Person.PersonOriginTypeId    = Convert.ToByte(json.PersonOriginTypeId);
                Person.PersonOriginDetails   = json.PersonOriginDetails.ToString();
                Person.CampaignId            = string.IsNullOrEmpty((json.CampaignId).Value) ? null : Convert.ToInt64(json.CampaignId);
                Person.CountryId             = Convert.ToByte(json.CountryId);
                Person.LanguageId            = Convert.ToByte(json.LanguageId);
                Person.PersonTypeId          = Convert.ToByte(json.PersonTypeId);
                Person.PersonProfileId       = Convert.ToByte(json.PersonProfileId);
                Person.PersonStatusId        = Convert.ToByte(json.PersonStatusId);
                Person.PersonalWebSite       = json.PersonalWebSite.ToString();
                Person.CurrencyId            = Convert.ToByte(json.CurrencyId);
                Person.CreationDateUTC       = DateTime.UtcNow;
                Person.ActivationCode        = json.ActivationCode.ToString();
                Person.ActivationDateUTC     = DateTime.UtcNow;
                Person.PhoneNumber           = json.PhoneNumber.ToString();
                Person.PersonFatherId        = string.IsNullOrEmpty((json.PersonFatherId).Value) ? null : int.Parse(json.PersonFatherId.ToString());
                Person.InviteId              = string.IsNullOrEmpty((json.InviteId).Value) ? null : Convert.ToInt64(json.InviteId);
                Person.ServerInstanceId      = Convert.ToInt16(json.ServerInstanceId);
                Person.Active                = true;
                Person.UserSystemId          = Convert.ToInt64(json.UserSystem);
                Person.PersonIntegrationID   = Guid.NewGuid();

                //};


                this.bus.Send(Person);


                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (System.Exception e)
            {
                LogManager.Error("Erro ao Add PersonAdd ", e);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
コード例 #13
0
        public void Handle(AddPersonCommand command)
        {
            var person = new Person {
                FirstName  = command.FirstName,
                MiddleName = command.MiddleName,
                LastName   = command.LastName,
                NIN        = command.NIN,
                Dob        = command.Dob
            };

            _dbContext.Add(person);
            _dbContext.SaveChanges();

            _commandStoreService.Push(command);
        }
コード例 #14
0
        public async void HandleAddPersonCommand_WithWrongDocumentCharCount_ShouldReturnDocumentCharCountError(string document, string name, string email, string phoneNumber)
        {
            //Arrange
            var sut = Mocker.CreateInstance <AddPersonCommandHandler>();


            var request = new AddPersonCommand(document, name, email, new List <string>()
            {
                phoneNumber
            });
            //Act
            await sut.Handle(request, new System.Threading.CancellationToken());

            //Assert
            DomainNotifications.GetAll().Should().NotBeEmpty();
            Mocker.GetMock <IPersonRepository>().Verify(x => x.AddPerson(It.IsAny <Person>()), Times.Never());
        }
コード例 #15
0
        public async void HandleAddPersonCommand_WithUser_ShouldReturnSuccessWithNoErrors()
        {
            //Arrange
            TestBaseArrangements baseArrangement = new TestBaseArrangements();

            #region build person
            string document    = "75115775122";
            string name        = "Andre Santarosa";
            string phoneNumber = "19999990000";
            string email       = "*****@*****.**";

            Person person = null;
            person = new Person(Guid.NewGuid(), document, name, email);
            List <PersonPhone> phones = new List <PersonPhone>();
            phones.Add(new PersonPhone(Guid.NewGuid(), phoneNumber, person));
            #endregion

            baseArrangement.Mocker.GetMock <IPersonRepository>()
            .Setup(u => u.GetByDocument(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(() => Task.FromResult <Person>(null));

            var sut           = baseArrangement.Mocker.CreateInstance <AddPersonCommandHandler>();
            var personCommand = new AddPersonCommand(document, name, email, new List <string>()
            {
                phoneNumber
            });

            //Act
            var addResponse = await sut.Handle(personCommand, new System.Threading.CancellationToken());

            //Assert
            baseArrangement.DomainNotifications.GetAll().Should().BeEmpty();
            addResponse.Should().NotBeNull();
            addResponse.PersonId.Should().NotBeEmpty().Should().NotBeNull();
            addResponse.PhoneNumbers.Should().HaveCountGreaterThan(0);
            baseArrangement.Mocker.GetMock <IPersonRepository>().Verify(x => x.GetByDocument(It.IsAny <string>(), It.IsAny <bool>()), Times.Once());
            baseArrangement.Mocker.GetMock <IPersonRepository>().Verify(x => x.AddPerson(It.IsAny <Person>()), Times.Once());
        }
コード例 #16
0
        public async Task <HttpResponseMessage> PersonProspectAdd()
        {
            //recebo as imagens se tiver
            try
            {
                var provider = new MultipartMemoryStreamProvider();
                NameValueCollection parameters = HttpContext.Current.Request.Params;
                if (Request.Content.IsMimeMultipartContent())
                {
                    try
                    {
                        await Request.Content.ReadAsMultipartAsync(provider);

                        fs = new List <FIleServer>();
                        int count = 0;
                        foreach (var file in HttpContext.Current.Request.Files)
                        {
                            var    f = provider.Contents[count];
                            string fileName;
                            if (f.Headers.ContentDisposition == null || f.Headers.ContentDisposition.FileName == null)
                            {
                                fileName = parameters["FileName"].ToString();
                            }
                            else
                            {
                                fileName = f.Headers.ContentDisposition.FileName.ToString().Replace("\"", "");
                            }


                            string mimeType      = new MimeType().GetMimeType(fileName);
                            var    stream        = (HttpContext.Current.Request.Files[count]).InputStream;
                            byte[] bytesInStream = new byte[stream.Length];
                            stream.Read(bytesInStream, 0, bytesInStream.Length);

                            Domain.ReadModel.FileTemp ft = new Domain.ReadModel.FileTemp();
                            ft.FileIntegrationCode = Guid.NewGuid();
                            ft.FilePath            = _storage.UploadFile(_containerName, ft.FileIntegrationCode.ToString(), mimeType, bytesInStream);
                            ft.OriginalName        = fileName;
                            try
                            {
                                using (Image img = Image.FromStream(stream: stream,
                                                                    useEmbeddedColorManagement: false,
                                                                    validateImageData: false))
                                {
                                    ft.Width  = img.PhysicalDimension.Width.ToString();
                                    ft.Height = img.PhysicalDimension.Height.ToString();
                                }
                                count++;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Error("Erro ao recuperar dimensoes da imagen", ex);
                            }


                            //salvo na tablea temporaria
                            try
                            {
                                _listFileTemp.Add(_FileTemp.SaveFileTemp(ft));
                            }
                            catch (Exception ex)
                            {
                                LogManager.Info("PersonProspectAdd sem Imagem");
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Error(string.Format("PersonProspectAdd image Error:{0}", ex));
                    }
                }



                var Person = new AddPersonCommand()
                {
                    IntegrationCode = Guid.NewGuid(),
                    Name            = parameters["Name"],
                    FantasyName     = parameters["FantasyName"].ToString(),
                    //NameFromSecurityCheck = parameters["NameFromSecurityCheck"].ToString(),
                    //SecuritySourceId =  parameters["SecuritySourceId"],
                    //IsSafe = parameters["IsSafe"],
                    //FriendlyNameURL = parameters["FriendlyNameURL"].ToString(),
                    PersonOriginTypeId = Convert.ToByte(parameters["PersonOriginTypeId"]),
                    //PersonOriginDetails = parameters["PersonOriginDetails"].ToString(),
                    CampaignId      = long.Parse(parameters["CampaignId"].ToString()),
                    CountryId       = Convert.ToByte(parameters["CountryId"]),
                    LanguageId      = Convert.ToByte(parameters["LanguageId"]),
                    PersonTypeId    = Convert.ToByte(parameters["PersonTypeId"]),
                    PersonProfileId = Convert.ToByte(parameters["PersonProfileId"]),
                    PersonStatusId  = Convert.ToByte(parameters["PersonStatusId"]),
                    //PersonalWebSite = parameters["PersonalWebSite.ToString(),
                    CurrencyId      = Convert.ToByte(parameters["CurrencyId"].ToString()),
                    CreationDateUTC = DateTime.UtcNow,
                    //ActivationCode = parameters["ActivationCode.ToString(),
                    //ActivationDateUTC = DateTime.Parse( parameters["ActivationDateUTC"].ToString()),
                    PhoneNumber = parameters["PhoneNumber"].ToString(),
                    //PersonFatherId = parameters["PersonFatherId,
                    InviteId            = long.Parse(parameters["InviteId"].ToString()),
                    ServerInstanceId    = Convert.ToInt16(1),
                    Active              = true,
                    listFileTemp        = _listFileTemp,
                    UserSystemId        = long.Parse(parameters["UserSystem"].ToString()),
                    PersonIntegrationID = Guid.NewGuid()
                                          //,ImgListId = _listFileTemp
                };


                this.bus.Send(Person);


                return(Request.CreateResponse(HttpStatusCode.OK, new { Person.PersonIntegrationID }));
            }
            catch (System.Exception ex)
            {
                LogManager.Error(string.Format("ValidateUser Error:{0}", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
コード例 #17
0
        public async Task <HttpResponseMessage> PersonProspectDesktopAdd()
        {
            //recebo as imagens se tiver
            try
            {
                var provider = new MultipartMemoryStreamProvider();
                NameValueCollection parameters = HttpContext.Current.Request.Params;
                if (Request.Content.IsMimeMultipartContent())
                {
                    try
                    {
                        await Request.Content.ReadAsMultipartAsync(provider);

                        fs = new List <FIleServer>();
                        int count = 0;
                        foreach (var file in HttpContext.Current.Request.Files)
                        {
                            var    f = provider.Contents[count];
                            string fileName;
                            if (f.Headers.ContentDisposition == null || f.Headers.ContentDisposition.FileName == null)
                            {
                                fileName = parameters["FileName"].ToString();
                            }
                            else
                            {
                                fileName = f.Headers.ContentDisposition.FileName.ToString().Replace("\"", "");
                            }


                            string mimeType      = new MimeType().GetMimeType(fileName);
                            var    stream        = (HttpContext.Current.Request.Files[count]).InputStream;
                            byte[] bytesInStream = new byte[stream.Length];
                            stream.Read(bytesInStream, 0, bytesInStream.Length);

                            Domain.ReadModel.FileTemp ft = new Domain.ReadModel.FileTemp();
                            ft.FileIntegrationCode = Guid.NewGuid();
                            ft.FilePath            = _storage.UploadFile(_containerName, ft.FileIntegrationCode.ToString(), mimeType, bytesInStream);
                            ft.OriginalName        = fileName;
                            try
                            {
                                using (Image img = Image.FromStream(stream: stream,
                                                                    useEmbeddedColorManagement: false,
                                                                    validateImageData: false))
                                {
                                    ft.Width  = img.PhysicalDimension.Width.ToString();
                                    ft.Height = img.PhysicalDimension.Height.ToString();
                                }
                                count++;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Error("Erro ao recuperar dimensoes da imagen", ex);
                            }


                            //salvo na tablea temporaria
                            try
                            {
                                _listFileTemp.Add(_FileTemp.SaveFileTemp(ft));
                            }
                            catch (Exception ex)
                            {
                                LogManager.Info("PersonProspectAdd sem Imagem");
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Error(string.Format("PersonProspectAdd image Error:{0}", ex));
                    }
                }
                if (!string.IsNullOrEmpty(parameters["CampaignId"].ToString()))
                {
                    campaignID = Convert.ToInt64(parameters["CampaignId"].ToString());
                }
                else
                {
                    campaignID = null;
                }

                if (!string.IsNullOrEmpty(parameters["InviteId"].ToString()))
                {
                    inviteId = long.Parse(parameters["InviteId"].ToString());
                }
                else
                {
                    inviteId = null;
                }


                var Person = new AddPersonCommand();

                Person.IntegrationCode     = Guid.NewGuid();
                Person.Name                = parameters["Name"];
                Person.FantasyName         = parameters["FantasyName"].ToString();
                Person.PersonOriginTypeId  = Convert.ToByte(parameters["PersonOriginTypeId"]);
                Person.CampaignId          = campaignID;
                Person.CountryId           = Convert.ToByte(parameters["CountryId"]);
                Person.LanguageId          = Convert.ToByte(parameters["LanguageId"]);
                Person.PersonTypeId        = Convert.ToByte(parameters["PersonTypeId"]);
                Person.PersonProfileId     = Convert.ToByte(parameters["PersonProfileId"]);
                Person.PersonStatusId      = Convert.ToByte(parameters["PersonStatusId"]);
                Person.CurrencyId          = Convert.ToByte(parameters["CurrencyId"].ToString());
                Person.CreationDateUTC     = DateTime.UtcNow;
                Person.PhoneNumber         = parameters["PhoneNumber"].ToString();
                Person.InviteId            = inviteId;
                Person.ServerInstanceId    = Convert.ToInt16(1);
                Person.Active              = true;
                Person.listFileTemp        = _listFileTemp;
                Person.UserSystemId        = long.Parse(parameters["UserSystem"].ToString());
                Person.PersonIntegrationID = Guid.NewGuid();
                Person.Number              = parameters["CNPJ"].ToString();//cnpj



                this.bus.Send(Person);


                List <int> expertiseId = new List <int>()
                {
                    Convert.ToInt32(parameters["ExpertiseId"].ToString())
                };
                var personExpertise = new AddPersonExpertiseCommand()
                {
                    ExpertiseListId   = expertiseId,
                    InsertedDateUTC   = DateTime.UtcNow,
                    InsertedBy        = Convert.ToInt32(parameters["UserSystem"].ToString()),
                    CustomDescription = parameters["CustomDescription"].ToString(),
                    ServerInstanceId  = 1,//Convert.ToInt16(json.ServerInstanceId),
                    //CustomPhotoFileId = string.IsNullOrEmpty(json.CustomPhotoFileId) ? null : json.CustomPhotoFileId,
                    //CustomDescription = json.CustomDescription,
                    ExhibitionOrder     = 1, // Convert.ToByte(json.ExhibitionOrder),
                    PersonIntegrationId = Person.PersonIntegrationID,
                    Active = true            //Convert.ToBoolean(json.Active)
                };

                this.bus.Send(personExpertise);



                return(Request.CreateResponse(HttpStatusCode.OK, new { Person.PersonIntegrationID }));
            }
            catch (System.Exception ex)
            {
                LogManager.Error(string.Format("ValidateUser Error:{0}", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
コード例 #18
0
 /// <summary>
 /// Checks if every command is executable.
 /// </summary>
 private void CheckCommands()
 {
     AddPersonCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
 }
コード例 #19
0
        public async Task <IActionResult> Add([FromBody] AddPersonCommand command)
        {
            await _mediator.Send(command);

            return(Ok());
        }
コード例 #20
0
 public async Task <IActionResult> Add([FromBody] AddPersonCommand command)
 {
     return(Ok(await HandleAsync(command)));
 }
コード例 #21
0
 public void Post(AddPersonCommand command)
 {
     Request(PersonListApiActions.Add, Method.POST, command);
 }
コード例 #22
0
        public async Task <IActionResult> AddPerson([FromBody] AddPersonCommand command)
        {
            RequestResult requestResult = await _orquestrator.SendCommand(command);

            return(await ReturnRequestResult(requestResult));
        }
コード例 #23
0
 public AddPersonViewModel(PeopleStore peopleStore, INavigationService closeNavigationService)
 {
     SubmitCommand = new AddPersonCommand(this, peopleStore, closeNavigationService);
     CancelCommand = new NavigateCommand(closeNavigationService);
 }
コード例 #24
0
 public AdvancedModel()
 {
     AddCommand    = new AddPersonCommand(this);
     CurrentPerson = new Person();
 }
コード例 #25
0
        public async Task <IActionResult> AddPerson(AddPersonCommand command)
        {
            var result = await _mediator.Send(command);

            return(await ReturnCommand(result));
        }