public ActionResult MyProfile() { ActionResult returnObject = null; String userId = User.Identity.GetUserId(); ModelMembers mMembers = new ModelMembers(this); ModelMembershipTypes mMembershipTypes = new ModelMembershipTypes(this); IList <MembershipTypes> listMembershipTypes = mMembershipTypes.GetListMembershipTypes(); List <SelectListItem> selectionMembershipTypes = new List <SelectListItem>(); foreach (MembershipTypes item in listMembershipTypes) { SelectListItem listItem = new SelectListItem(); listItem.Value = item.Id.ToString(); listItem.Text = item.MembershipType; selectionMembershipTypes.Add(listItem); } if (mMembers.IsProfileExist(userId) == true) { Members rMember = mMembers.GetRecordByUserId(userId); ViewModelUserProfile profile = new ViewModelUserProfile(rMember); profile.listMembershipTypes = selectionMembershipTypes; returnObject = View("MyProfile", profile); } else { ViewModelUserProfile profile = new ViewModelUserProfile(); profile.UserId = userId; profile.listMembershipTypes = selectionMembershipTypes; returnObject = View("MyProfile", profile); } return(returnObject); }
/* * While the statistical information like DateJOined etc are set to default values it is assumed that the new record will be added * to the database and not be used tooverwrite an existing record. The ModelMembers.Update method calls Members.Assign() to move * Member record data to a record just retrieved from the database and then writing it back. In this way statistical information * is not overwritten inadvertently. The intent is to have special functions in ModelMembers that can be called to specifically * update the statistical information. */ public Members(ViewModelUserProfile vmRecord) { Id = vmRecord.Id; Surname = vmRecord.Surname; FirstName = vmRecord.FirstName; MiddleNames = vmRecord.MiddleNames; Address1 = vmRecord.Address1; Address2 = vmRecord.Address2; Suburb = vmRecord.Suburb; State = vmRecord.State; Postcode = vmRecord.PostCode; Phone = vmRecord.Phone; Email = vmRecord.Email; Mobile = vmRecord.Mobile; MembershipTypesId = Int32.Parse(vmRecord.MembershipTypesId.ToString()); DiscordName = vmRecord.DiscordName; DiscordId = vmRecord.DiscordId; AspNetUserId = vmRecord.UserId; DateJoined = DateTime.Today; FinancialYN = false; MembershipExpiry = DateTime.ParseExact("01/01/2000", "d/M/yyyy", CultureInfo.InvariantCulture); LastLoggedIn = DateTime.ParseExact("01/01/2000", "d/M/yyyy", CultureInfo.InvariantCulture); }
public ActionResult MyProfile(ViewModelUserProfile vmProfile) { ActionResult returnObject = null; String userId = User.Identity.GetUserId(); ModelMembers mMembers = new ModelMembers(this); bool successYN = true; while (true) { if (ModelState.IsValid == false) { successYN = false; break; } if (mMembers.IsProfileExist(userId) == true) { if (mMembers.GetRecordByUserId(userId).Id != vmProfile.Id) { ModelState.AddModelError("", "Profile ID doesn't match the expected Profile ID of Logged In User. Possible hacking attempt"); successYN = false; break; } Members rMember = new Members(vmProfile); if (mMembers.Update(rMember) == false) { ModelState.AddModelError("", mMembers.exception); successYN = false; break; } } else { Members rMember = new Members(vmProfile); if (mMembers.Insert(rMember) == false) { ModelState.AddModelError("", mMembers.exception.GetBaseException().Message); successYN = false; break; } } break; } if (successYN == true) { returnObject = RedirectToAction("Index", "Manage"); } else { ModelMembershipTypes mMembershipTypes = new ModelMembershipTypes(this); IList <MembershipTypes> listMembershipTypes = mMembershipTypes.GetListMembershipTypes(); List <SelectListItem> selectionMembershipTypes = new List <SelectListItem>(); foreach (MembershipTypes item in listMembershipTypes) { SelectListItem listItem = new SelectListItem(); listItem.Value = item.Id.ToString(); listItem.Text = item.MembershipType; if (vmProfile.MembershipTypesId == item.Id) { listItem.Selected = true; } selectionMembershipTypes.Add(listItem); } vmProfile.listMembershipTypes = selectionMembershipTypes; returnObject = View("MyProfile", vmProfile); } return(returnObject); }