public async Task <IActionResult> Profile(string id, bool readOnlyView = false) { ProfileViewModelVM model = new ProfileViewModelVM(); ApplicationUser1ModelVM user = new ApplicationUser1ModelVM(); try { if (readOnlyView != false) { ViewBag.readOnlyView = true; } if (id != null) { user.applicationUser = _context.Users.Where(u => u.Id == id).SingleOrDefault(); ViewBag.AdminEdit = true; } else { user.applicationUser = await _userManager.GetUserAsync(User); } if (user.applicationUser == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } else { model = ProfileManager.Profile(_context, user, StatusMessage); var roles = await _userManager.GetRolesAsync(user.applicationUser); model.UserRole = roles[0]; if (model.UserRole == "Aggregator") { model.applicationUsers = await ShowAggregatorsFarmers(); } return(View(model)); } } catch (Exception ex) { // Do something here return(View(model)); } }
public async Task <IActionResult> Attachments(ProfileViewModelVM model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } #region Data Assignment if (model.profileViewModel.ProfilePicture != user.ProfilePicture) { user.ProfilePicture = model.profileViewModel.ProfilePicture; } if (model.profileViewModel.Fingerprint != user.Fingerprint) { user.Fingerprint = model.profileViewModel.Fingerprint; } if (model.profileViewModel.ScannedID != user.ScannedID) { user.ScannedID = model.profileViewModel.ScannedID; } if (model.profileViewModel.ScannedIDComment != user.ScannedIDComment) { user.ScannedIDComment = model.profileViewModel.ScannedIDComment; } #endregion await _userManager.UpdateAsync(user); StatusMessage = "Your Data has been Uploaded."; return(RedirectToAction(nameof(Attachments))); }
public static ProfileViewModelVM Attachments(ApplicationUser user, string StatusMessage) { var Model = new ProfileViewModelVM(); Model.BlobUri = ConfigurationManager.GetAppSetting("BlobUri"); Model.SAS = ConfigurationManager.GetAppSetting("SAS"); Model.Container = ConfigurationManager.GetAppSetting("Container"); Model.profileViewModel = new ProfileViewModel { ProfilePicture = user.ProfilePicture, Fingerprint = user.Fingerprint, ScannedID = user.ScannedID, ScannedIDComment = user.ScannedIDComment, StatusMessage = StatusMessage, }; return(Model); }
public static ProfileViewModelVM Profile(ApplicationDbContext _context, ApplicationUser1ModelVM user, string StatusMessage) { var Model = new ProfileViewModelVM(); var mapCoord = ""; var markers = _context.Markers.Where(u => u.UserId == user.applicationUser.Id).SingleOrDefault(); if (markers != null) { Model.Markers = markers.LatLng; mapCoord = markers.LatLng; } else { Model.Markers = "Empty"; } var model = new ProfileViewModel { FirstName = user.applicationUser.FirstName, LastName = user.applicationUser.LastName, // Farmer_Id_Form_No = user.Farmer_Id_Form_No, Dob = user.applicationUser.Dob, Username = user.applicationUser.UserName, County = user.applicationUser.County, SubCounty = user.applicationUser.SubCounty, Ward = user.applicationUser.Ward, PhoneNumber = user.applicationUser.PhoneNumber, Mpesa_No = user.applicationUser.Mpesa_No, // Gender = user.Gender, KraPin = user.applicationUser.KraPin, Whatapp_No = user.applicationUser.Whatapp_No, Bank_Info = user.applicationUser.Bank_Info, Next_of_Kin = user.applicationUser.Next_of_Kin, Next_of_Kin_Contact = user.applicationUser.Next_of_Kin_Contact, Acreage = user.applicationUser.Acreage, Field_Coords = mapCoord, Crop = user.applicationUser.Crop, Email = user.applicationUser.Email, IsEmailConfirmed = user.applicationUser.EmailConfirmed, WalletAddress = user.applicationUser.WalletAddress, StatusMessage = StatusMessage, NationalIDNumber = user.applicationUser.NationalIDNumber, SerialFormNumber = user.applicationUser.SerialFormNumber, InputUsed = user.applicationUser.InputUsed, PlantingDate = user.applicationUser.PlantingDate, Aggregator_Company = user.applicationUser.Aggregator_Company, Company_Registration_Number = user.applicationUser.CompanyRegistrationNumber, Field_pin = user.applicationUser.Field_Pin, Economic_Activity = user.applicationUser.Economic_Activity, Household_Size = user.applicationUser.Household_Size, Disability_Type = user.applicationUser.DisabilityType, Farmer_Id_Form_No = user.applicationUser.Farmer_Id_Form_No, Input_Service = user.applicationUser.InputService, supplier_Company = user.applicationUser.supplier_Company, Planting_Season = user.applicationUser.PlantingSeason }; model.Yield_Quantity = Convert.ToInt32(user.applicationUser.YieldQuantity); Model.profileViewModel = model; return(Model); }
public async Task <IActionResult> Profile(ProfileViewModelVM model, string id) { //if (!ModelState.IsValid) //{ // return View(model); //} ApplicationUser user = null; if (id != null) { user = _context.Users.Where(u => u.Id == id).SingleOrDefault(); } else { user = await _userManager.GetUserAsync(User); } if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } //Only allow unique wallet addresses if (model.profileViewModel.WalletAddress != null) { var existingWallets = _context.Users.Where(p => p.WalletAddress == model.profileViewModel.WalletAddress).ToList(); if (existingWallets.Count != 0) { if (existingWallets.Count > 1) { StatusMessage = "Error: This wallet address is already in use.Please use a different Wallet Address"; return(RedirectToAction(nameof(Profile))); // throw new ApplicationException("This wallet address is already in use. Please use a different Wallet Address"); } } } if (model.profileViewModel.Email != user.Email) { var setEmailResult = await _userManager.SetEmailAsync(user, model.profileViewModel.Email); if (!setEmailResult.Succeeded) { StatusMessage = "Error: This Email address is already in use.Please use a different Email Address"; return(RedirectToAction(nameof(Profile))); } } if (model.profileViewModel.Username != user.UserName) { //GetUserNameAsync var setUsernameResult = await _userManager.SetUserNameAsync(user, model.profileViewModel.Username); if (!setUsernameResult.Succeeded) { StatusMessage = "Error: This UserName is already in use.Please use a different UserName"; return(RedirectToAction(nameof(Profile))); } } //if (model.PhoneNumber != null) //{ // var existingphonenumber = _context.Users.Where(p => p.PhoneNumber == model.PhoneNumber).ToList(); // if (existingphonenumber.Count != 0) // { // if (existingphonenumber.Count > 1) // { // StatusMessage = "Error: This Phone Number is already in use. Please use a different Phone Number."; // return RedirectToAction(nameof(Profile)); // // throw new ApplicationException("This wallet address is already in use. Please use a different Wallet Address"); // } // } // var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber); // user.PhoneNumber = model.PhoneNumber; // user.UserName = model.PhoneNumber; //} //else //{ // StatusMessage = "Error: Phone Number cannot be empty"; // return RedirectToAction(nameof(Profile)); //} #region DataAssignment if (model.profileViewModel.FirstName != user.FirstName && model.profileViewModel.FirstName != null) { user.FirstName = model.profileViewModel.FirstName; } if (model.profileViewModel.LastName != user.LastName && model.profileViewModel.LastName != null) { user.LastName = model.profileViewModel.LastName; } if (model.profileViewModel.Email != user.Email) { user.Email = model.profileViewModel.Email; } if (model.profileViewModel.Username != user.UserName) { user.UserName = model.profileViewModel.Username; } if (model.profileViewModel.PhoneNumber != user.PhoneNumber) { user.PhoneNumber = model.profileViewModel.PhoneNumber; } if (model.profileViewModel.Farmer_Id_Form_No != user.Farmer_Id_Form_No) { user.Farmer_Id_Form_No = model.profileViewModel.Farmer_Id_Form_No; } if (user.Dob != model.profileViewModel.Dob) { user.Dob = model.profileViewModel.Dob; } if (model.profileViewModel.County != user.County) { user.County = model.profileViewModel.County; } if (model.profileViewModel.SubCounty != user.SubCounty) { user.SubCounty = model.profileViewModel.SubCounty; } if (model.profileViewModel.Ward != user.Ward) { user.Ward = model.profileViewModel.Ward; } if (model.profileViewModel.Mpesa_No != user.Mpesa_No) { user.Mpesa_No = model.profileViewModel.Mpesa_No; } if (model.profileViewModel.Whatapp_No != user.Whatapp_No) { user.Whatapp_No = model.profileViewModel.Whatapp_No; } if (model.profileViewModel.Bank_Info != user.Bank_Info) { user.Bank_Info = model.profileViewModel.Bank_Info; } if (model.profileViewModel.KraPin != user.KraPin) { user.KraPin = model.profileViewModel.KraPin; } if (model.profileViewModel.Next_of_Kin != user.Next_of_Kin) { user.Next_of_Kin = model.profileViewModel.Next_of_Kin; } if (model.profileViewModel.Next_of_Kin_Contact != user.Next_of_Kin_Contact) { user.Next_of_Kin_Contact = model.profileViewModel.Next_of_Kin_Contact; } if (model.profileViewModel.Acreage != user.Acreage) { user.Acreage = model.profileViewModel.Acreage; } if (model.profileViewModel.mapCoords != user.Field_Coords) { user.Field_Coords = model.profileViewModel.mapCoords; } if (model.profileViewModel.Crop != user.Crop) { user.Crop = model.profileViewModel.Crop; } if (model.profileViewModel.WalletAddress != user.WalletAddress) { user.WalletAddress = model.profileViewModel.WalletAddress; } if (model.profileViewModel.NationalIDNumber != user.NationalIDNumber) { user.NationalIDNumber = model.profileViewModel.NationalIDNumber; } if (model.profileViewModel.SerialFormNumber != user.SerialFormNumber) { user.SerialFormNumber = model.profileViewModel.SerialFormNumber; } if (model.profileViewModel.InputUsed != user.InputUsed) { user.InputUsed = model.profileViewModel.InputUsed; } if (model.profileViewModel.PlantingDate != user.PlantingDate) { user.PlantingDate = model.profileViewModel.PlantingDate; } if (model.profileViewModel.Aggregator_Company != user.Aggregator_Company) { user.Aggregator_Company = model.profileViewModel.Aggregator_Company; } if (model.profileViewModel.Company_Registration_Number != user.CompanyRegistrationNumber) { user.CompanyRegistrationNumber = model.profileViewModel.Company_Registration_Number; } if (model.profileViewModel.Field_pin != user.Field_Pin) { user.Field_Pin = model.profileViewModel.Field_pin; } if (model.profileViewModel.Economic_Activity != user.Economic_Activity) { user.Economic_Activity = model.profileViewModel.Economic_Activity; } if (model.profileViewModel.Household_Size != user.Household_Size) { user.Household_Size = model.profileViewModel.Household_Size; } if (model.profileViewModel.Disability_Type != user.DisabilityType) { user.DisabilityType = model.profileViewModel.Disability_Type; } if (model.profileViewModel.Farmer_Id_Form_No != user.Farmer_Id_Form_No) { user.Farmer_Id_Form_No = model.profileViewModel.Farmer_Id_Form_No; } if (model.profileViewModel.Input_Service != user.InputService) { user.InputService = model.profileViewModel.Input_Service; } if (model.profileViewModel.Planting_Season != user.PlantingSeason) { user.PlantingSeason = model.profileViewModel.Planting_Season; } if (model.profileViewModel.supplier_Company != user.supplier_Company) { user.supplier_Company = model.profileViewModel.supplier_Company; } if (model.profileViewModel.Yield_Quantity != Convert.ToInt32(user.YieldQuantity)) { user.YieldQuantity = Convert.ToString(model.profileViewModel.Yield_Quantity); } #endregion await _userManager.UpdateAsync(user); var markers = _context.Markers.Where(u => u.UserId == user.Id).SingleOrDefault(); if (markers != null) { markers.LatLng = model.profileViewModel.mapCoords; await _context.SaveChangesAsync(); } else { var area = new MarkerModel(); area.UserId = user.Id; area.LatLng = model.profileViewModel.mapCoords; _context.Add(area); _context.SaveChanges(); } StatusMessage = "Your profile has been updated"; return(RedirectToAction(nameof(Profile), new { id = id })); }