public async Task <IActionResult> InitProfileInfoAsync(ProfileInfoModel profileInfo) { using var connection = new MySqlConnection(AppConfig.Constants.DbConnectionString); using var command = new MySqlCommand("PutProfileInfo", connection) { CommandType = CommandType.StoredProcedure }; command.Parameters.AddRange(new[] { new MySqlParameter("user_id", MyId), new MySqlParameter("post", profileInfo.Post), new MySqlParameter("location", profileInfo.Location), new MySqlParameter("age", profileInfo.Age), new MySqlParameter("sex", profileInfo.Sex), new MySqlParameter("rel_status", profileInfo.RelationshipStatus), new MySqlParameter("sex_preference", profileInfo.SexPreference), new MySqlParameter("smoking_attitude", profileInfo.AttitudeToSmoking), new MySqlParameter("alcohol_attitude", profileInfo.AttitudeToAlcohol), new MySqlParameter("biography", profileInfo.Biography), //TODO: убрать new MySqlParameter("error_message", MySqlDbType.VarChar) { Direction = ParameterDirection.ReturnValue } }); connection.Open(); await command.ExecuteNonQueryAsync(); var errorMessage = command.Parameters["error_message"].Value.ToString(); if (string.IsNullOrEmpty(errorMessage) == false) { return(new ResponseModel(HttpStatusCode.Conflict, errorMessage).ToResult()); } return(ResponseModel.OK.ToResult()); }
public async Task <IActionResult> UpdateInfoAsync(ProfileInfoModel profileInfo) { using var connection = new MySqlConnection(AppConfig.Constants.DbConnectionString); using var command = new MySqlCommand("UpdateProfileInfo", connection) { CommandType = CommandType.StoredProcedure }; command.Parameters.AddRange(new[] { new MySqlParameter("user_id", MyId), new MySqlParameter("name", profileInfo.Name), new MySqlParameter("surname", profileInfo.Surname), new MySqlParameter("age", profileInfo.Age), new MySqlParameter("post", profileInfo.Post), new MySqlParameter("location", profileInfo.Location) }); connection.Open(); await command.ExecuteNonQueryAsync(); return(ResponseModel.OK.ToResult()); }
public ActionResult Info(int customerProfileId) { var customer = _customerService.GetCustomerById(customerProfileId); if (customer == null) { return(HttpNotFound()); } //avatar bool avatarEnabled = false; string avatarUrl = _pictureService.GetFallbackUrl(_mediaSettings.AvatarPictureSize, FallbackPictureType.Avatar); if (_customerSettings.AllowCustomersToUploadAvatars) { avatarEnabled = true; var customerAvatarId = customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId); if (customerAvatarId != 0) { avatarUrl = _pictureService.GetUrl(customerAvatarId, _mediaSettings.AvatarPictureSize, false); } else { if (!_customerSettings.DefaultAvatarEnabled) { avatarEnabled = false; } } } //location bool locationEnabled = false; string location = string.Empty; if (_customerSettings.ShowCustomersLocation) { locationEnabled = true; var countryId = customer.GetAttribute <int>(SystemCustomerAttributeNames.CountryId); var country = _countryService.GetCountryById(countryId); if (country != null) { location = country.GetLocalized(x => x.Name); } else { locationEnabled = false; } } //private message bool pmEnabled = _forumSettings.AllowPrivateMessages && !customer.IsGuest(); //total forum posts bool totalPostsEnabled = false; int totalPosts = 0; if (_forumSettings.ForumsEnabled && _forumSettings.ShowCustomersPostCount) { totalPostsEnabled = true; totalPosts = customer.GetAttribute <int>(SystemCustomerAttributeNames.ForumPostCount); } //registration date bool joinDateEnabled = false; string joinDate = string.Empty; if (_customerSettings.ShowCustomersJoinDate) { joinDateEnabled = true; joinDate = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } //birth date bool dateOfBirthEnabled = false; string dateOfBirth = string.Empty; if (_customerSettings.DateOfBirthEnabled) { var dob = customer.BirthDate; if (dob.HasValue) { dateOfBirthEnabled = true; dateOfBirth = dob.Value.ToString("D"); } } var model = new ProfileInfoModel() { CustomerProfileId = customer.Id, AvatarEnabled = avatarEnabled, AvatarUrl = avatarUrl, LocationEnabled = locationEnabled, Location = location, PMEnabled = pmEnabled, TotalPostsEnabled = totalPostsEnabled, TotalPosts = totalPosts.ToString(), JoinDateEnabled = joinDateEnabled, JoinDate = joinDate, DateOfBirthEnabled = dateOfBirthEnabled, DateOfBirth = dateOfBirth, }; return(PartialView(model)); }
/// <summary> /// Prepare the profile info model /// </summary> /// <param name="customer">Customer</param> /// <returns>Profile info model</returns> public virtual ProfileInfoModel PrepareProfileInfoModel(Customer customer) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } //avatar var avatarUrl = ""; if (_customerSettings.AllowCustomersToUploadAvatars) { avatarUrl = _pictureService.GetPictureUrl( _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar); } //location var locationEnabled = false; var location = string.Empty; if (_customerSettings.ShowCustomersLocation) { locationEnabled = true; var countryId = _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.CountryIdAttribute); var country = _countryService.GetCountryById(countryId); if (country != null) { location = _localizationService.GetLocalized(country, x => x.Name); } else { locationEnabled = false; } } //private message var pmEnabled = _forumSettings.AllowPrivateMessages && !customer.IsGuest(); //total forum posts var totalPostsEnabled = false; var totalPosts = 0; if (_forumSettings.ForumsEnabled && _forumSettings.ShowCustomersPostCount) { totalPostsEnabled = true; totalPosts = _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.ForumPostCountAttribute); } //registration date var joinDateEnabled = false; var joinDate = string.Empty; if (_customerSettings.ShowCustomersJoinDate) { joinDateEnabled = true; joinDate = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } //birth date var dateOfBirthEnabled = false; var dateOfBirth = string.Empty; if (_customerSettings.DateOfBirthEnabled) { var dob = _genericAttributeService.GetAttribute <DateTime?>(customer, NopCustomerDefaults.DateOfBirthAttribute); if (dob.HasValue) { dateOfBirthEnabled = true; dateOfBirth = dob.Value.ToString("D"); } } var model = new ProfileInfoModel { CustomerProfileId = customer.Id, AvatarUrl = avatarUrl, LocationEnabled = locationEnabled, Location = location, PMEnabled = pmEnabled, TotalPostsEnabled = totalPostsEnabled, TotalPosts = totalPosts.ToString(), JoinDateEnabled = joinDateEnabled, JoinDate = joinDate, DateOfBirthEnabled = dateOfBirthEnabled, DateOfBirth = dateOfBirth, }; return(model); }
internal static async Task <string> UploadProfileImg(IWebHostEnvironment webHost, ProfileInfoModel profileData) { string imgName = null; if (profileData.profilePicture != null) { imgName = Guid.NewGuid().ToString() + "_" + profileData.profilePicture.FileName; var filePath = Path.Combine(webHost.WebRootPath, "img", "Profile", imgName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await profileData.profilePicture.CopyToAsync(fileStream); } } return(imgName); }
public async Task <IViewComponentResult> InvokeAsync(string customerProfileId) { var customer = await _customerService.GetCustomerById(customerProfileId); if (customer == null) { return(Content("")); } //avatar var avatarUrl = ""; if (_customerSettings.AllowCustomersToUploadAvatars) { avatarUrl = await _pictureService.GetPictureUrl( customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType : PictureType.Avatar); } //location bool locationEnabled = false; string location = string.Empty; if (_customerSettings.ShowCustomersLocation) { locationEnabled = true; var countryId = customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.CountryId); var country = await _countryService.GetCountryById(countryId); if (country != null) { location = country.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id); } else { locationEnabled = false; } } //private message bool pmEnabled = _forumSettings.AllowPrivateMessages && !customer.IsGuest(); //total forum posts bool totalPostsEnabled = false; int totalPosts = 0; if (_forumSettings.ForumsEnabled && _forumSettings.ShowCustomersPostCount) { totalPostsEnabled = true; totalPosts = customer.GetAttributeFromEntity <int>(SystemCustomerAttributeNames.ForumPostCount); } //registration date bool joinDateEnabled = false; string joinDate = string.Empty; if (_customerSettings.ShowCustomersJoinDate) { joinDateEnabled = true; joinDate = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } //birth date bool dateOfBirthEnabled = false; string dateOfBirth = string.Empty; if (_customerSettings.DateOfBirthEnabled) { var dob = customer.GetAttributeFromEntity <DateTime?>(SystemCustomerAttributeNames.DateOfBirth); if (dob.HasValue) { dateOfBirthEnabled = true; dateOfBirth = dob.Value.ToString("D"); } } var model = new ProfileInfoModel { CustomerProfileId = customer.Id, AvatarUrl = avatarUrl, LocationEnabled = locationEnabled, Location = location, PMEnabled = pmEnabled, TotalPostsEnabled = totalPostsEnabled, TotalPosts = totalPosts.ToString(), JoinDateEnabled = joinDateEnabled, JoinDate = joinDate, DateOfBirthEnabled = dateOfBirthEnabled, DateOfBirth = dateOfBirth, }; return(View(model)); }