public async Task <ActionResult> EditProfile() { var userid = CurrentUser.UserId; if (CurrentUser.UserType == UserType.SystemAdmin) { var response = await WepApiMethod.SendApiAsync <DetailsUserModel>(HttpVerbs.Get, $"Administration/User?id={userid}"); if (response.Data == null) { return(new HttpStatusCodeResult(404)); } var model = new EditAdminProfileModel { Name = response.Data.Name, Email = response.Data.Email, MobileNo = response.Data.MobileNo, CountryCode = response.Data.CountryCode }; return(View("EditProfileAdmin", model)); } else if (CurrentUser.UserType == UserType.Individual) { var response = await WepApiMethod.SendApiAsync <DetailsIndividualModel>(HttpVerbs.Get, $"Administration/Individual?id={userid}"); if (response.Data == null) { return(new HttpStatusCodeResult(404)); } var model = new EditIndividualProfileModel { IsMalaysian = response.Data.IsMalaysian, CitizenshipId = response.Data.Citizenship != null ? response.Data.Citizenship.Id : (int?)null, Name = response.Data.Name, ICNo = response.Data.ICNo, PassportNo = response.Data.PassportNo, MobileNo = response.Data.MobileNo, CountryCode = response.Data.CountryCode, Address1 = response.Data.Address1, Address2 = response.Data.Address2, PostCodeMalaysian = response.Data.PostCodeMalaysian, PostCodeNonMalaysian = response.Data.PostCodeNonMalaysian, City = response.Data.City, StateId = response.Data.State.Id, State = response.Data.State.Name, CountryId = response.Data.Country.Id }; var countries = await GetCountries(); model.MalaysiaCountryId = countries.Where(c => c.Name == "Malaysia").Select(s => s.Id).FirstOrDefault(); model.States = new SelectList(await GetStates(), "Id", "Name", 0); model.Countries = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0); model.Citizenships = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0); return(View("EditProfileIndividual", model)); } else if (CurrentUser.UserType == UserType.Company) { var response = await WepApiMethod.SendApiAsync <DetailsCompanyModel>(HttpVerbs.Get, $"Administration/Company?id={userid}"); if (response.Data == null) { return(new HttpStatusCodeResult(404)); } var model = new EditCompanyProfileModel { Type = response.Data.Type, CompanyName = response.Data.CompanyName, AgencyName = response.Data.AgencyName, MinistryId = response.Data.Ministry != null ? response.Data.Ministry.Id : (int?)null, SectorId = response.Data.Sector != null ? response.Data.Sector.Id : (int?)null, CompanyRegNo = response.Data.CompanyRegNo, Address1 = response.Data.Address1, Address2 = response.Data.Address2, PostCodeMalaysian = response.Data.PostCodeMalaysian, PostCodeNonMalaysian = response.Data.PostCodeNonMalaysian, City = response.Data.City, StateId = response.Data.State.Id, State = response.Data.State.Name, CountryId = response.Data.Country.Id, CompanyPhoneNo = response.Data.CompanyPhoneNo, Name = response.Data.Name, ICNo = response.Data.ICNo, PassportNo = response.Data.PassportNo, MobileNo = response.Data.MobileNo, CountryCode = response.Data.CountryCode, }; var countries = await GetCountries(); model.MalaysiaCountryId = countries.Where(c => c.Name == "Malaysia").Select(s => s.Id).FirstOrDefault(); model.Sectors = new SelectList(await GetSectors(), "Id", "Name", 0); model.States = new SelectList(await GetStates(), "Id", "Name", 0); model.Ministries = new SelectList(await GetMinistry(), "Id", "Name", 0); model.Countries = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0); return(View("EditProfileCompany", model)); } return(RedirectToAction("MyProfile", "Home", new { area = "" })); }
public async Task <ActionResult> EditProfile(int?id) { if (CurrentUser.UserType == UserType.SystemAdmin) { var model = new EditAdminProfileModel(); if (TryUpdateModel(model)) { var modelapi = new EditUserModel(); modelapi.Name = model.Name; modelapi.MobileNo = model.MobileNo; var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"Administration/User?id={CurrentUser.UserId}", modelapi); if (response.Data) { await LogActivity(Modules.Setting, "Update Profile", model); TempData["SuccessMessage"] = Language.Profile.AlertSuccessUpdateProfile; return(RedirectToAction("MyProfile", "Home", new { area = "" })); } } } else if (CurrentUser.UserType == UserType.Individual) { var model = new EditIndividualProfileModel(); TryUpdateModel(model); if (model.IsMalaysian) { ModelState.Remove("PassportNo"); ModelState.Remove("CitizenshipId"); ModelState.Remove("PostCodeNonMalaysian"); ModelState.Remove("State"); ModelState.Remove("CountryId"); model.CountryId = model.MalaysiaCountryId; } else { ModelState.Remove("ICNo"); ModelState.Remove("PostCodeMalaysian"); ModelState.Remove("StateId"); model.StateId = null; } if (ModelState.IsValid) { var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"Home/Profile/EditIndividualProfile?id={CurrentUser.UserId}", model); if (response.Data) { await LogActivity(Modules.Setting, "Update Profile", model); TempData["SuccessMessage"] = Language.Profile.AlertSuccessUpdateProfile; return(RedirectToAction("MyProfile", "Home", new { area = "" })); } } var countries = await GetCountries(); model.MalaysiaCountryId = countries.Where(c => c.Name == "Malaysia").Select(s => s.Id).FirstOrDefault(); model.States = new SelectList(await GetStates(), "Id", "Name", 0); model.Countries = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0); model.Citizenships = new SelectList(countries.Where(c => c.Name != "Malaysia"), "Id", "Name", 0); return(View("EditProfileIndividual", model)); } else if (CurrentUser.UserType == UserType.Company) { var model = new EditCompanyProfileModel(); TryUpdateModel(model); if (model.Type == CompanyType.Government) { ModelState.Remove("PassportNo"); ModelState.Remove("PostCodeNonMalaysian"); ModelState.Remove("State"); ModelState.Remove("CountryId"); ModelState.Remove("CompanyName"); ModelState.Remove("CompanyRegNo"); ModelState.Remove("SectorId"); model.CountryId = model.MalaysiaCountryId; } else if (model.Type == CompanyType.MalaysianCompany) { ModelState.Remove("PassportNo"); ModelState.Remove("PostCodeNonMalaysian"); ModelState.Remove("State"); ModelState.Remove("CountryId"); ModelState.Remove("AgencyName"); ModelState.Remove("MinistryId"); model.CountryId = model.MalaysiaCountryId; } else { ModelState.Remove("ICNo"); ModelState.Remove("PostCodeMalaysian"); ModelState.Remove("StateId"); ModelState.Remove("AgencyName"); ModelState.Remove("MinistryId"); ModelState.Remove("CompanyRegNo"); } if (ModelState.IsValid) { var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"Home/Profile/EditCompanyProfile?id={CurrentUser.UserId}", model); if (response.Data) { await LogActivity(Modules.Setting, "Update Profile", model); TempData["SuccessMessage"] = Language.Profile.AlertSuccessUpdateProfile; return(RedirectToAction("MyProfile", "Home", new { area = "" })); } } model.Sectors = new SelectList(await GetSectors(), "Id", "Name", 0); return(View("EditProfileCompany", model)); } return(RedirectToAction("MyProfile", "Home", new { area = "" })); }
public IHttpActionResult EditIndividualProfile(int id, [FromBody] EditIndividualProfileModel model) { var user = db.User.Where(u => u.Id == id && u.Display).FirstOrDefault(); var individual = db.IndividualProfile.Where(i => i.UserId == id).FirstOrDefault(); if (user == null || individual == null) { return(NotFound()); } if (model.IsMalaysian) { ModelState.Remove("model.PassportNo"); ModelState.Remove("model.CitizenshipId"); ModelState.Remove("model.PostCodeNonMalaysian"); ModelState.Remove("model.State"); } else { ModelState.Remove("model.ICNo"); ModelState.Remove("model.PostCodeMalaysian"); ModelState.Remove("model.StateId"); } var countryCode = db.Country.Where(c => c.Id == model.CountryId && c.Display).FirstOrDefault(); if (countryCode == null) { return(InternalServerError()); } if (ModelState.IsValid) { user.Name = model.Name; user.ICNo = model.ICNo; user.MobileNo = model.MobileNo; user.CountryCode = countryCode.CountryCode1; individual.IsMalaysian = model.IsMalaysian; individual.CitizenshipId = model.CitizenshipId; individual.Address1 = model.Address1; individual.Address2 = model.Address2; individual.PostCode = model.IsMalaysian ? model.PostCodeMalaysian : model.PostCodeNonMalaysian; individual.City = model.City; individual.StateId = model.IsMalaysian ? model.StateId : null; individual.StateName = model.IsMalaysian ? "" : model.State; individual.CountryId = model.CountryId; db.User.Attach(user); db.Entry(user).Property(x => x.Name).IsModified = true; db.Entry(user).Property(x => x.ICNo).IsModified = true; db.Entry(user).Property(x => x.MobileNo).IsModified = true; db.Entry(user).Property(x => x.CountryCode).IsModified = true; db.Entry(individual).State = EntityState.Modified; db.Configuration.ValidateOnSaveEnabled = true; db.SaveChanges(); return(Ok(true)); } return(BadRequest(ModelState)); }