예제 #1
0
        public async Task <ActionResult <UserPersonDTO> > Get()
        {
            var  user   = User.Claims.ToList();
            Guid UserId = Guid.Parse(user.FirstOrDefault(x => x.Type == "id").Value);

            UserPersonDTO userPerson = await _personService.GetPersonAsync(UserId);

            if (userPerson != null)
            {
                return(Ok(userPerson));
            }

            return(NotFound(new { message = "User not found" }));
        }
예제 #2
0
        public async Task <UserPersonDTO> InsertPersonAsync(Person userPerson)
        {
            UserPersonDTO infoUser = new UserPersonDTO();

            try
            {
                userPerson.User.Id = Guid.NewGuid();
                userPerson.Id      = Guid.NewGuid();
                await _dbContext.Users.AddAsync(userPerson.User);

                await _dbContext.People.AddAsync(userPerson);

                var savePerson = await _dbContext.SaveChangesAsync();

                if (savePerson == 2)
                {
                    List <Person> people = await _dbContext.People.ToListAsync();

                    List <User> users = await _dbContext.Users.ToListAsync();

                    UserPersonDTO newPerson = (from person in people
                                               join user in users
                                               on person.UserID equals user.Id
                                               select new UserPersonDTO()
                    {
                        Id = person.Id,
                        Name = person.Name,
                        LastName = person.LastName,
                        Country = person.Country,
                        Gender = person.Gender,
                        UserId = user.Id,
                        Email = user.Email,
                    }).FirstOrDefault();

                    infoUser = newPerson;
                }
                else
                {
                    infoUser = null;
                }
            }
            catch
            {
                return(infoUser = null);
            }

            return(infoUser);
        }
예제 #3
0
        public async Task <UserPersonDTO> GetPersonAsync(Guid id)
        {
            UserPersonDTO userPerson = new UserPersonDTO();

            try
            {
                Person person = await _dbContext.People.Where(p => p.UserID == id).SingleOrDefaultAsync();

                if (person != null)
                {
                    User user = await _dbContext.Users.Where(p => p.Id == person.UserID).SingleOrDefaultAsync();

                    person.User = user;

                    userPerson = new UserPersonDTO()
                    {
                        Id       = person.Id,
                        Name     = person.Name,
                        LastName = person.LastName,
                        Country  = person.Country,
                        Gender   = person.Gender,
                        UserId   = user.Id,
                        Email    = user.Email,
                    };
                }
                else
                {
                    userPerson = null;
                }
            }
            catch
            {
                userPerson = null;
            }
            return(userPerson);
        }