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 EditCompanyProfile(int id, [FromBody] EditCompanyProfileModel model) { if (model.Type == CompanyType.Government) { ModelState.Remove("model.PassportNo"); ModelState.Remove("model.PostCodeNonMalaysian"); ModelState.Remove("model.State"); ModelState.Remove("model.CountryId"); ModelState.Remove("model.CompanyName"); ModelState.Remove("model.CompanyRegNo"); ModelState.Remove("model.SectorId"); } else if (model.Type == CompanyType.MalaysianCompany) { ModelState.Remove("model.PassportNo"); ModelState.Remove("model.PostCodeNonMalaysian"); ModelState.Remove("model.State"); ModelState.Remove("model.CountryId"); ModelState.Remove("model.AgencyName"); ModelState.Remove("model.MinistryId"); } else { ModelState.Remove("model.ICNo"); ModelState.Remove("model.PostCodeMalaysian"); ModelState.Remove("model.StateId"); ModelState.Remove("model.AgencyName"); ModelState.Remove("model.MinistryId"); ModelState.Remove("model.CompanyRegNo"); } var countryCode = db.Country.Where(c => c.Id == model.CountryId && c.Display).FirstOrDefault(); if (countryCode == null) { return(InternalServerError()); } if (ModelState.IsValid) { var user = db.User.Where(u => u.Id == id).FirstOrDefault(); var company = db.CompanyProfile.Where(c => c.UserId == id).FirstOrDefault(); if (user == null || company == null) { return(NotFound()); } user.Name = model.Name; user.ICNo = model.Type == CompanyType.NonMalaysianCompany ? model.PassportNo : model.ICNo; user.MobileNo = model.MobileNo; user.CountryCode = countryCode.CountryCode1; company.Type = model.Type; company.MinistryId = model.MinistryId; company.CompanyName = model.Type == CompanyType.Government ? model.AgencyName : model.CompanyName; company.CompanyRegNo = model.CompanyRegNo; company.SectorId = model.SectorId; company.Address1 = model.Address1; company.Address2 = model.Address2; company.City = model.City; company.StateId = model.StateId; company.StateName = model.State; company.PostCode = model.Type != CompanyType.NonMalaysianCompany ? model.PostCodeNonMalaysian : model.PostCodeMalaysian; company.CompanyPhoneNo = model.CompanyPhoneNo; company.CountryCode = countryCode.CountryCode1; 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(company).State = EntityState.Modified; db.Configuration.ValidateOnSaveEnabled = true; db.SaveChanges(); return(Ok(true)); } return(BadRequest(ModelState)); }