示例#1
0
        /// <summary>
        /// Returns user profile dto inside response dto
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public ResponseDto <UserProfileDto> GetUserProfileById(int?id)
        {
            using (var profileContext = new IndividualProfileContext())
            {
                // Find profile associated with account
                var dbUserProfile = (from profile in profileContext.UserProfiles
                                     where profile.UserAccount.Id == id
                                     select profile).SingleOrDefault();

                ResponseDto <UserProfileDto> responseDto = new ResponseDto <UserProfileDto>
                {
                    Data  = new UserProfileDto(dbUserProfile),
                    Error = null
                };

                return(responseDto);
            }
        }
示例#2
0
        /// <summary>
        /// Returns true if update process succeeds, false if fails
        /// </summary>
        /// <param name="userProfileDto"></param>
        /// <returns></returns>
        public ResponseDto <bool> EditUserProfileById(int?userAccountId, UserProfile userProfileDomain)
        {
            using (var profileContext = new IndividualProfileContext())
            {
                var dbUserProfile = (from profile in profileContext.UserProfiles
                                     where profile.Id == userAccountId
                                     select profile).SingleOrDefault();

                using (var dbContextTransaction = profileContext.Database.BeginTransaction())
                {
                    try
                    {
                        // Apply and save changes
                        dbUserProfile.DisplayName = userProfileDomain.DisplayName;
                        profileContext.SaveChanges();
                        dbContextTransaction.Commit();

                        ResponseDto <bool> responseDto = new ResponseDto <bool>
                        {
                            Data  = true,
                            Error = null
                        };
                        return(responseDto);
                    }

                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();

                        ResponseDto <bool> responseDto = new ResponseDto <bool>
                        {
                            Data  = false,
                            Error = GeneralErrorMessages.GENERAL_ERROR
                        };
                        return(responseDto);
                    }
                }
            }
        }