Exemple #1
0
        public void CreatePerson_ValidationError_Tagsの要素が重複()
        {
            var requestObject = new PersonCreateRequest
            {
                PersonCode  = new String('Z', 20),
                Name        = new String('Z', 256),
                LoginId     = new String('Z', 256),
                Title       = new String('Z', 100),
                Description = new String('Z', 1026),
                Status      = "NORMAL",
                SortNo      = 0,
                Tags        = new List <string> {
                    "1", "1",
                },
            };

            var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/persons");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(requestObject), Encoding.UTF8, "application/json");
            var response     = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var responseBody = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var error        = JsonUtil.Deserialize <Error>(responseBody);

            Assert.AreEqual(ErrorCodes.ValidationError, error.Code);
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("Tags", StringComparison.OrdinalIgnoreCase)));
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemple #2
0
        public void DeletePerson_OK_正常値で削除()
        {
            var requestObject = new PersonCreateRequest
            {
                PersonCode  = new String('T', 20),
                Name        = new String('X', 256),
                LoginId     = new String('T', 256),
                Title       = new String('X', 100),
                Description = new String('X', 1024),
                Status      = PersonStatus.NORMAL.ToString(),
                SortNo      = int.MaxValue,
                Tags        = new List <string> {
                    new String('X', 100)
                },
            };

            var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/persons");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(requestObject), Encoding.UTF8, "application/json");
            var response     = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var responseBody = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var person       = JsonUtil.Deserialize <Person>(responseBody);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            request = new HttpRequestMessage(HttpMethod.Delete, $"/api/v1/persons/{person.PersonId}");
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            response = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        public IActionResult CreatePerson([FromBody] PersonCreateRequest personCreateRequest)
        {
            Person person = _mapper.Map <Person>(personCreateRequest);

            _entityRepository.Add(person);
            _unitOfWork.Commit();
            return(Ok());
        }
 public Person(PersonCreateRequest personCreateRequest)
 {
     personId  = Guid.NewGuid();
     CreatedAt = DateTime.UtcNow;
     Age       = personCreateRequest.Age;
     EmailId   = personCreateRequest.EmailId;
     Fullname  = personCreateRequest.Fullname;
     Password  = personCreateRequest.Password;
 }
        public async Task <Result <int> > UpdateAsync(PersonCreateRequest model, int id = 0)
        {
            var result = new Result <int>();

            try
            {
                var person = _mapper.Map <Person>(model);

                if (id > 0)
                {
                    var existingNumbers = await _uow.PhoneNumbers.GetByPersonIdAsync(id);

                    person.Id       = id;
                    person.ImageUrl = await _uow.Persons.GetImageUrlAsync(person.Id);

                    if (person.PhoneNumbers?.Any() == true)
                    {
                        var numbersToDelete = existingNumbers.Where(en => en.Id != 0 && person.PhoneNumbers.All(n => n.Id != en.Id));
                        if (numbersToDelete.Any())
                        {
                            _uow.PhoneNumbers.DeleteRange(numbersToDelete);
                        }

                        var numbersToUpdate = person.PhoneNumbers.Where(n => n.Id != 0 && existingNumbers.Any(en => en.Id == n.Id));
                        if (numbersToUpdate.Any())
                        {
                            _uow.PhoneNumbers.UpdateRange(numbersToUpdate);
                        }

                        var numbersToAdd = person.PhoneNumbers.Where(n => n.Id == 0);
                        if (numbersToAdd.Any())
                        {
                            _uow.PhoneNumbers.AddRange(numbersToAdd);
                        }
                    }

                    _uow.Persons.Update(person);
                }
                else
                {
                    _uow.Persons.Add(person);
                }

                await _uow.SaveAsync();

                _logger.LogInformation($"{nameof(PersonsService)} => {nameof(UpdateAsync)} | Person added successfully | Id: {id}");
                result.Data = person.Id;
            }
            catch (Exception ex)
            {
                _logger.LogError($"{nameof(PersonsService)} => {nameof(UpdateAsync)} | Person have not added successfully | Id: {id} | ex: {ex.ToString()} | trace: {ex.StackTrace.ToString()}");

                result.AddError(ErrorMessages.InternalServerError, HttpStatusCode.InternalServerError);
            }
            return(result);
        }
Exemple #6
0
 public Person(PersonCreateRequest personCreateRequest)
 {
     PersonId       = Guid.NewGuid();
     FirstName      = personCreateRequest.FirstName;
     GraduationDate = personCreateRequest.GraduationDate;
     EmailId        = personCreateRequest.EmailId;
     gender         = personCreateRequest.gender;
     CreatedAt      = DateTime.UtcNow;
     Password       = personCreateRequest.Password;
 }
Exemple #7
0
        public async Task <PersonResponse> Create(PersonCreateRequest request)
        {
            if (await _personRepository.IsPersonExists(request.FirstName, request.LastName))
            {
                throw new PersonAlreadyExists("This person already exists!");
            }

            var person = await _personRepository.Create(_mapper.Map <Person>(request));

            return(_mapper.Map <PersonResponse>(person));
        }
 public Person CreatePerson(PersonCreateRequest personCreateRequest)
 {
     try
     {
         var Person = new Person(personCreateRequest);
         var cred   = new Credentials(new CredentialCreateRequest(personCreateRequest.Fullname, personCreateRequest.Password));
         _cred.InsertOneAsync(cred).Wait();
         _person.InsertOneAsync(Person).Wait();
         return(Person);
     }
     catch { throw; }
 }
        public Person MapCreateRequestToEntity(PersonCreateRequest request)
        {
            var person = new Person
            {
                FirstName   = request.FirstName,
                LastName    = request.LastName,
                Email       = request.Email,
                PhoneNumber = request.PhoneNumber,
                CompanyId   = request.CompanyId,
            };

            return(person);
        }
Exemple #10
0
        void IPersonManager.Update(int id, PersonCreateRequest item)
        {
            var result = new Person
            {
                Id        = id,
                FirstName = item.FirstName,
                LastName  = item.LastName,
                Email     = item.Email,
                Company   = item.Company,
                Age       = item.Age
            };

            _personRepo.Update(result);
        }
Exemple #11
0
        int IPersonManager.Create(PersonCreateRequest item)
        {
            var rnd    = new Random();
            var result = new Person()
            {
                Id        = rnd.Next(51, 100),
                FirstName = item.FirstName,
                LastName  = item.LastName,
                Email     = item.Email,
                Company   = item.Company,
                Age       = item.Age
            };

            _personRepo.Add(result);
            return(result.Id);
        }
Exemple #12
0
        public async Task <IActionResult> Create([FromBody] PersonCreateRequest request)
        {
            try
            {
                var person = await _personService.Create(request);

                return(Ok(person));
            }
            catch (PersonAlreadyExists exception)
            {
                return(BadRequest(new
                {
                    exception.Message
                }));
            }
        }
        public ActionResult <string> Post([FromBody] PersonCreateRequest personCreateRequest)
        {
            var sw     = Stopwatch.StartNew();
            var person = personServices.CreatePerson(personCreateRequest);

            if (person == null)
            {
                return("Email ID already exist. Please try different ID");
            }
            var credentialCreateRequest = new CredentialsCreateRequest(person);

            credentialService.CreateCredentials(credentialCreateRequest);
            sw.Stop();
            LoginDuration
            .WithLabels("Create_Person")
            .Observe(sw.Elapsed.TotalSeconds);
            return("User Created ID: " + person.PersonId.ToString());
        }
Exemple #14
0
        private Guid CreatePerson(string firstName, string lastName, DateTime birthDate)
        {
            PersonCreateRequest request = new PersonCreateRequest()
            {
                FirstName = firstName,
                LastName  = lastName,
                BirthDate = birthDate
            };

            manager.CreatePerson(request);

            Person person = manager.LoadPerson <Person>(request.Id);

            Assert.AreEqual(request.FirstName, person.FirstName);
            Assert.AreEqual(request.LastName, person.LastName);
            Assert.AreEqual(request.BirthDate, person.BirthDate);

            return(request.Id);
        }
        public ActionResult <Person> CreatePerson([FromBody] PersonCreateRequest request)
        {
            if (_personQueryService.ExistsPersonCode(request.PersonCode))
            {
                return(ErrorObjectResultFactory.ValidationErrorDetail(
                           string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayPersonPersonCode),
                           "personCode"));
            }

            if (_personQueryService.ExistsLoginId(request.LoginId))
            {
                return(ErrorObjectResultFactory.ValidationErrorDetail(
                           string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayPersonLoginId),
                           "loginId"));
            }

            var dto    = _mapper.Map <PersonCreateRequest, PersonCreateDto>(request);
            var entity = _personService.CreatePerson(dto);

            return(_mapper.Map <Domain.Entities.Person, Person>(entity));
        }
Exemple #16
0
        public async Task <IActionResult> PostPerson(PersonCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400));
            }

            var identityClaimNum = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);



            var dto = _mapper.Map <PersonCreateDTO>(request);

            dto.DateCreated = DateTime.Now;

            if (await _manager.CreatePerson(dto))
            {
                return(StatusCode(201));
            }

            throw new Exception();
        }
Exemple #17
0
        public void CreateFamily()
        {
            Guid motherId = CreatePerson("Amy", "Elston", new DateTime(1986, 6, 6));
            Guid fatherId = CreateMyself();

            PersonCreateRequest childCreateRequest = new PersonCreateRequest()
            {
                FirstName = "Liam",
                LastName  = "Elston",
                BirthDate = new DateTime(2014, 5, 17)
            };

            manager.AddChild(motherId, fatherId, childCreateRequest);

            Parent mother = manager.LoadPerson <Parent>(motherId);
            Parent father = manager.LoadPerson <Parent>(fatherId);

            Assert.NotNull(mother.Children);
            Assert.AreEqual(1, mother.Children.Count());

            CreateFamily_Asserts();
        }
Exemple #18
0
        public Person CreatePerson(PersonCreateRequest personCreateRequest)
        {
            try
            {
                var personDocument = new Person(personCreateRequest);
                if (!IsUserAvailable(personDocument.EmailId))
                {
                    return(null);
                }
                _person.InsertOneAsync(personDocument).Wait();

                var credentials = new Credentials();
                //UserGauge.WithLabels(host).Inc();
                UserPostCounter.Inc();
                UserGauge.Inc();
                return(personDocument);
            }
            catch
            {
                System.Console.WriteLine("Create person service failed");
                throw;
            }
        }
Exemple #19
0
 public ActionResult <PersonModel> Create(PersonCreateRequest request)
 {
     return(Ok(PersonService.Create(request)));
 }
Exemple #20
0
        public PersonModel Create(PersonCreateRequest request)
        {
            var entity = PersonRepository.Create(PersonMapper.MapCreateRequestToEntity(request));

            return(PersonMapper.MapEntityToModel(entity));
        }
Exemple #21
0
 public ActionResult <Person> Create([FromBody] PersonCreateRequest personCreateRequest)
 {
     return(personServices.CreatePerson(personCreateRequest));
 }
        public IActionResult Create([FromBody] PersonCreateRequest value)
        {
            var id = _personManager.Create(value);

            return(Ok(id));
        }
 public IActionResult Update([FromRoute] int id, [FromBody]  PersonCreateRequest value)
 {
     _personManager.Update(id, value);
     return(Ok());
 }