public async Task <Contact> GetByIdWithState(Guid userId)
        {
            var dbUser = DbUser;

            using (UserProfileRepository _userProfileRepository = new UserProfileRepository(Context, dbUser, null))
                using (UserContactRepository _userContactRepository = new UserContactRepository(Context, dbUser, null))
                {
                    var user = _userProfileRepository.GetById(userId);
                    if (user != null)
                    {
                        var userContact = _userContactRepository.GetByContactUserId(user.Id, dbUser);
                        return(new Contact()
                        {
                            Id = user.Id,
                            Email = user.Email,
                            FirstName = user.FirstName,
                            LastName = user.LastName,
                            State = userContact?.State,
                            ProfileImageString = Request.GetFileUrl((int)FileType.Profile, user.ProfileImageString)
                        });
                    }

                    return(new Contact());
                }
        }
示例#2
0
        public async Task <IdResult> ChangeInvitationState(Contact invitorUserProfile)
        {
            if (invitorUserProfile == null)
            {
                return(new IdResult()
                {
                    IsOk = false,
                    ErrorMessage = "No user info"
                });
            }
            var dbUser = DbUser;

            using (UserContactRepository _userContactRepository = new UserContactRepository(Context, dbUser, null))
                using (UserProfileRepository _userProfileRepository = new UserProfileRepository(Context, dbUser, null))
                {
                    var invitorUserProfileFromDb = _userProfileRepository.GetById(invitorUserProfile.Id);

                    if (invitorUserProfile.Id != Guid.Empty && invitorUserProfileFromDb != null)
                    {
                        var userContactDB = _userContactRepository.GetByContactUserId(invitorUserProfileFromDb.Id, dbUser);
                        if (userContactDB != null)
                        {
                            userContactDB.State     = invitorUserProfile.State;
                            userContactDB.StateDate = DateTime.Now;

                            var senderUser = _userProfileRepository.GetById(userContactDB.MainUserId);
                            if (invitorUserProfile.State == (byte)InvitationStates.Accepted)
                            {
                                _userContactRepository.Create(new UserContact()
                                {
                                    ContactName   = senderUser.FullName,
                                    ContactUserId = senderUser.Id,
                                    MainUserId    = dbUser,
                                    State         = (int)InvitationStates.Accepted,
                                    StateDate     = DateTime.Now
                                });

                                Utilities.AddNotification(dbUser, userContactDB.MainUserId, dbUser, (int)NotificationTypes.InvitationToContactsConfirmed,
                                                          string.Format("You invitaion is accepted"));
                            }
                            Context.SaveChanges();
                            return(new IdResult()
                            {
                                IsOk = true,
                                Id = userContactDB.Id,
                            });
                        }
                    }
                }

            return(new IdResult()
            {
                IsOk = false,
                ErrorMessage = "Error"
            });
            //var user = JsonConvert.DeserializeObject<UserRegister>(userData);
        }