示例#1
0
        public async Task <ProfileCRUDDTO> GetUserProfileDataAsync(string mobile)
        {
            var person = await _personService.GetPersonByMobileAsync(mobile);

            if (person == null)
            {
                throw new AwroNoreException(NewResource.UserNotFound);
            }

            var result = new ProfileCRUDDTO
            {
                Id             = person.Id,
                FirstName      = person.FirstName,
                SecondName     = person.SecondName,
                ThirdName      = person.ThirdName,
                Age            = (int)person.Age,
                Birthdate      = person.Birthdate,
                Email          = person.Email,
                FullName       = person.FullName,
                Gender         = person.Gender,
                Height         = person.Height ?? 0,
                IdNumber       = person.IdNumber ?? "",
                Language       = person.Language,
                MarriageStatus = person.MarriageStatus,
                Mobile         = person.Mobile,
                Username       = person.Mobile,
                Weight         = person.Weight ?? 0,
                Address        = person.Address,
                Avatar         = person.RealAvatar,
                HasAvatar      = !string.IsNullOrEmpty(person.Avatar)
            };

            return(result);
        }
        public async Task <IActionResult> CreateOrUpdateUser([FromBody] ProfileCRUDDTO profile)
        {
            if (string.IsNullOrEmpty(CurrentUserName))
            {
                return(Unauthorized());
            }

            if (!CurrentUserName.Equals(profile.Mobile))
            {
                return(Unauthorized());
            }

            profile.IdentityUserId = IdentityUserId;

            profile.Username = CurrentUserName;

            var result = await _profileService.CreateOrUpdateUserProfileAsync(profile);

            result.IsDoctor = User.IsInRole("doctor");

            return(Ok(result));
        }
示例#3
0
        public async Task <ProfileStatusDTO> CreateOrUpdateUserProfileAsync(ProfileCRUDDTO profile)
        {
            var person = await _personService.GetPersonByMobileAsync(profile.Mobile);

            if (person == null) // Create new user profile
            {
                person = new Person
                {
                    FirstName       = profile.FirstName,
                    FirstName_Ku    = profile.FirstName,
                    FirstName_Ar    = profile.FirstName,
                    SecondName      = profile.SecondName,
                    SecondName_Ar   = profile.SecondName,
                    SecondName_Ku   = profile.SecondName,
                    ThirdName       = profile.ThirdName,
                    ThirdName_Ar    = profile.ThirdName,
                    ThirdName_Ku    = profile.ThirdName,
                    Age             = profile.Age,
                    Address         = profile.Address,
                    Birthdate       = profile.Birthdate,
                    Gender          = profile.Gender,
                    Height          = profile.Height,
                    Language        = profile.Language,
                    MarriageStatus  = profile.MarriageStatus,
                    Mobile          = profile.Mobile,
                    IdNumber        = profile.IdNumber,
                    Weight          = profile.Weight,
                    CreatedAt       = DateTime.Now,
                    IsApproved      = true,
                    IsDeleted       = false,
                    Email           = profile.Email,
                    IsEmployee      = false,
                    MobileConfirmed = true,
                    IdentityUsers   = new List <IdentityUser>
                    {
                        new IdentityUser
                        {
                            UserId    = profile.IdentityUserId,
                            UserName  = profile.Username,
                            Email     = profile.Email,
                            CreatedAt = DateTime.Now
                        }
                    }
                };

                if (!string.IsNullOrEmpty(profile.FcmToken))
                {
                    person.FcmInstanceIds = new List <FcmInstanceIdModel>
                    {
                        new FcmInstanceIdModel
                        {
                            InstanceId = profile.FcmToken,
                            IsOn       = true
                        }
                    };
                }

                person.UniqueId = await _personService.GenerateUniqueIdAsync();

                _personService.InsertNewPerson(person);
            }
            else
            {
                person.FirstName       = profile.FirstName;
                person.FirstName_Ar    = profile.FirstName;
                person.FirstName_Ku    = profile.FirstName;
                person.SecondName      = profile.SecondName;
                person.SecondName_Ar   = profile.SecondName;
                person.SecondName_Ku   = profile.SecondName;
                person.ThirdName       = profile.ThirdName;
                person.ThirdName_Ar    = profile.ThirdName;
                person.ThirdName_Ku    = profile.ThirdName;
                person.Age             = profile.Age;
                person.Birthdate       = profile.Birthdate;
                person.Address         = profile.Address;
                person.IdNumber        = profile.IdNumber;
                person.Weight          = profile.Weight;
                person.Height          = profile.Height;
                person.MarriageStatus  = profile.MarriageStatus;
                person.Language        = profile.Language;
                person.Gender          = profile.Gender;
                person.Email           = profile.Email;
                person.MobileConfirmed = true;
                person.UpdatedAt       = DateTime.Now;

                _personService.UpdatePerson(person);
            }

            var result = new ProfileStatusDTO
            {
                Id             = person.Id,
                IdentityUserId = profile.IdentityUserId,
                FullName       = person.FullName,
                Username       = person.Mobile,
                Email          = person.Email,
                Mobile         = person.Mobile,
                IsNewUser      = false,
                Avatar         = person.RealAvatar,
                HasAvatar      = !string.IsNullOrEmpty(person.Avatar)
            };

            return(result);
        }