public ProfileValidation AddProfile(string firstName, string lastName, string email) { Profile newProfile = new Profile { FirstName = firstName, LastName = lastName, Email = email }; ProfileValidation returnValue = ValidateProfile(newProfile); if (returnValue != ProfileValidation.Valid) { return(returnValue); } _profiles.Append(newProfile); return(ProfileValidation.Valid); }
public ActionResult Account() { var thisUser = DB.Account.Single(x => x.Id == CurrentUser.Id); var model = new ProfileValidation() { AppointmentId = thisUser.AppointmentId, CompanyName = thisUser.AccountCompany.Name, EmailDomain = thisUser.AccountCompany.CompanyDomainName.FirstOrDefault(x => x.Name == thisUser.Login.Split('@')[1])?.Id, Mailname = thisUser.Login.Split('@')[0], PhoneNumber = thisUser.Phone, LastName = thisUser.LastName, FirstName = thisUser.FirstName, OtherName = thisUser.OtherName }; var appointmentList = DB.AccountAppointment.Where(x => x.GlobalEnabled) .Select(x => new OptionElement { Text = x.Name, Value = x.Id.ToString() }) .ToList(); // добавили кастомную должность, если есть var userOptionAppointment = DB.AccountAppointment.SingleOrDefault(x => x.Id == CurrentUser.AppointmentId && !x.GlobalEnabled); if (userOptionAppointment != null) { appointmentList.Add(new OptionElement { Value = userOptionAppointment.Id.ToString(), Text = userOptionAppointment.Name }); } ViewBag.AppointmentList = appointmentList; ViewBag.DomainList = DB.CompanyDomainName .Where(x => x.CompanyId == CurrentUser.CompanyId) .ToList() .Select(x => new OptionElement { Text = '@' + x.Name, Value = x.Id.ToString() }) .ToList(); return(View(model)); }
private async Task <ProfileValidation> ValidateProfile(Signup model) { var validation = new ProfileValidation(); using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(5); var result = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, model.ProfileLink)); if (result.IsSuccessStatusCode && !result.RequestMessage.RequestUri.AbsoluteUri.Contains("MvpSearch")) { var doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(await result.Content.ReadAsStreamAsync()); var divElements = doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("class")); // Try to verify that the name matches. var title = WebUtility.HtmlDecode(divElements.Where(d => d.Attributes["class"].Value.Contains("profile")).SingleOrDefault()?.Descendants("div").FirstOrDefault()?.InnerText.Trim()); validation.NameFound = title; validation.NameExpected = model.FullName; validation.NameVerified = title.Contains(model.FullName); bool?foundMatchingEmailAddress = null; // Try to verify that the email address matches. foreach (var emailAddressElement in divElements.Where(d => d.Attributes["class"].Value.Contains("otherPanel")).SingleOrDefault()?.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("mail"))) { if (String.Compare(emailAddressElement.InnerText.Trim(), model.Email) == 0) { foundMatchingEmailAddress = true; break; } foundMatchingEmailAddress = false; } validation.EmailVerified = foundMatchingEmailAddress; } } return(validation); }
public async Task <IActionResult> GetBusinessProfile(string accountId) { _logger.LogInformation(LoggingEvents.HttpGet, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name); _logger.LogDebug(LoggingEvents.HttpGet, "accountId: {accountId}"); List <LegalEntity> legalEntities; var expand = new List <string> { "primarycontactid" }; var account = (_dynamicsClient.Accounts.Get(filter: "", expand: expand).Value.FirstOrDefault()).ToViewModel(); _logger.LogDebug(LoggingEvents.HttpGet, "Account details: " + JsonConvert.SerializeObject(account)); // get legal entities var entityFilter = $"_adoxio_account_value eq {accountId}"; var expandList = new List <string> { "adoxio_ShareholderAccountID" }; try { legalEntities = _dynamicsClient.Adoxiolegalentities.Get(filter: entityFilter, expand: expandList).Value .Select(le => { var legalEntity = le.ToViewModel(); var entity = new ViewModels.LegalEntity { AdoxioLegalEntity = legalEntity, Account = le.AdoxioShareholderAccountID == null ? account : le.AdoxioShareholderAccountID.ToViewModel(), }; entity.corporateDetailsFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Corporate Information").Result; entity.organizationStructureFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Organization Structure").Result; entity.keyPersonnelFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Key Personnel").Result; entity.financialInformationFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Financial Information").Result; entity.shareholderFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Central Securities Register").Result; var tiedHouse = _dynamicsClient.AdoxioTiedhouseconnections .Get(filter: $"_adoxio_accountid_value eq {entity.Account.id}") .Value.FirstOrDefault(); if (tiedHouse != null) { entity.TiedHouse = tiedHouse.ToViewModel(); } entity.ChildEntities = GetLegalEntityChildren(entity.AdoxioLegalEntity.id); return(entity); }) .ToList(); } catch (OdataerrorException odee) { _logger.LogError(LoggingEvents.Error, "Error getting legal entities for the account {accountId}."); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); return(null); } var profile = new BusinessProfile { Account = account, LegalEntities = legalEntities }; var isComplete = legalEntities.Select(le => { var valid = new ProfileValidation { LegalEntityId = le.AdoxioLegalEntity.id, IsComplete = (le.IsComplete()) }; return(valid); }).ToList(); _logger.LogDebug(LoggingEvents.HttpGet, "BusinessProfile.isComplete: " + JsonConvert.SerializeObject(isComplete, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); return(Json(isComplete)); }
public ActionResult Account(ProfileValidation model) { var domain = DB.CompanyDomainName.Single(x => x.Id == model.EmailDomain).Name; var newLogin = $"{model.Mailname}@{domain}"; var ea = new EmailAddressAttribute(); if (!ea.IsValid(newLogin)) { ModelState.AddModelError("Mailname", "Неверный формат email"); } if (!ModelState.IsValid) { var appointmentList = DB.AccountAppointment.Where(x => x.GlobalEnabled) .Select(x => new OptionElement { Text = x.Name, Value = x.Id.ToString() }) .ToList(); // добавили кастомную должность, если есть var userOptionAppointment = DB.AccountAppointment.SingleOrDefault(x => x.Id == CurrentUser.AppointmentId && !x.GlobalEnabled); if (userOptionAppointment != null) { appointmentList.Add(new OptionElement { Value = userOptionAppointment.Id.ToString(), Text = userOptionAppointment.Name }); } ViewBag.AppointmentList = appointmentList; ViewBag.DomainList = DB.CompanyDomainName .Where(x => x.CompanyId == CurrentUser.CompanyId) .ToList() .Select(x => new OptionElement { Text = '@' + x.Name, Value = x.Id.ToString() }) .ToList(); return(View(model)); } var accountSave = DB.Account.Single(x => x.Id == CurrentUser.Id); var changeLogin = accountSave.Login != newLogin; accountSave.Name = $"{model.LastName} {model.FirstName} {model.OtherName}"; accountSave.LastName = model.LastName; accountSave.FirstName = model.FirstName; accountSave.OtherName = model.OtherName; accountSave.Login = newLogin; accountSave.Phone = model.PhoneNumber; accountSave.AppointmentId = model.AppointmentId; DB.SaveChanges(); if (changeLogin) { CurrentUser = accountSave; FormsAuthentication.SetAuthCookie(CurrentUser.Login, true); } SuccessMessage("Ваш профиль сохранен"); return(RedirectToAction("Index", "Profile")); }