public ActionResult Create() { AssociateViewModel objAssociateViewModel = new AssociateViewModel(); objAssociateViewModel.Specializations = _associateService.GetSpecializationsAll(); return(View(objAssociateViewModel)); }
public AssociateViewModel GetAssociateById(int associateId) { Associate associate = _associateRepo.GetAssociateById(associateId); if (associate != null) { AssociateViewModel associateViewModel = new AssociateViewModel { AssociateId = associate.AssociateId, AssociateName = associate.AssociateName, AssociateAddress = associate.AssociateAddress, AssociatePhone = associate.AssociatePhone, specializationIds = associate.Specializations.Select(x => x.SpecializationId).ToList(), Specializations = _associateRepo.GetSpecializaionsAll().Select(s => new SpecializationViewModel { SpecializationId = s.SpecializationId, SpecializationName = s.SpecializationName }).ToList() }; return(associateViewModel); } //else part later else { return(null); } }
public ActionResult Create([Bind(Include = "AssociateId,AssociateName,AssociatePhone,AssociateAddress,specializationIds")] AssociateViewModel associateViewModel) { if (associateViewModel.specializationIds == null) { ModelState.AddModelError("Specializations", "Please select specialization"); } if (ModelState.IsValid) { _associateService.SaveAssociate(associateViewModel); return(RedirectToAction("Index")); } else { associateViewModel.Specializations = _associateService.GetSpecializationsAll(); return(View(associateViewModel)); } }
public void SaveAssociate(AssociateViewModel associateViewModel) { try { Associate objAssociate = new Associate() { AssociateId = associateViewModel.AssociateId, AssociateName = associateViewModel.AssociateName, AssociateAddress = associateViewModel.AssociateAddress, AssociatePhone = associateViewModel.AssociatePhone, Specializations = _associateRepo.GetSpecializaions(associateViewModel) }; _associateRepo.SaveAssociate(objAssociate); } catch (Exception e) { } }
public string GenerateJSONWebToken(AssociateViewModel request) { var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var claims = new List <Claim>() { new Claim(ClaimTypes.Name, request.Id.ToString()), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(ClaimTypes.Role, request.Role) }; var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], claims.ToArray(), expires: DateTime.Now.AddMinutes(30), signingCredentials: credentials); return(new JwtSecurityTokenHandler().WriteToken(token)); }
public ActionResult Edit(int?id) { if (id == null) { return(View("BadRequest")); } else { try { AssociateViewModel associateViewModel = _associateService.GetAssociateById(id.Value); CreateSummaryOfIds(associateViewModel); return(View(associateViewModel)); } catch { throw; } } }
public ActionResult Associate(AssociateViewModel model) { if (ModelState.IsValid) { string userId = User.Identity.GetUserId(); Project project = _db.Projects.Single(p => p.Id == model.SelectedProjectId); // Not using UserManager because both objects need to be referenced from the same instance of db-context... // ... for Many-to-Many-relationhips to be inserted properly. ApplicationUser user = _db.Users.Single(u => u.Id == userId); project.AssociatedUsers.Add(user); _db.Projects.Attach(project); _db.Entry(project).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Startup", "Report", new { associatedProjectId = project.Id })); } return(View(model)); }
public async Task <ResultVM> Associate([FromBody] AssociateViewModel associate) { // Create a new account.. if (!associate.associateExistingAccount) { var user = new IdentityUser { Id = Guid.NewGuid().ToString(), UserName = associate.Username, Email = associate.OriginalEmail }; var createUserResult = await _userManager.CreateAsync(user); if (createUserResult.Succeeded) { // Add the Trial claim.. Claim trialClaim = new Claim("Trial", DateTime.Now.ToString()); await _userManager.AddClaimAsync(user, trialClaim); createUserResult = await _userManager.AddLoginAsync(user, new ExternalLoginInfo(null, associate.LoginProvider, associate.ProviderKey, associate.ProviderDisplayName)); if (createUserResult.Succeeded) { // Rule #2 user.EmailConfirmed = true; await _userManager.UpdateAsync(user); await _signInManager.ExternalLoginSignInAsync(associate.LoginProvider, associate.ProviderKey, false); return(new ResultVM { Status = Status.Success, Message = $"{user.UserName} has been created successfully", Data = new { username = user.UserName } }); } } var resultErrors = createUserResult.Errors.Select(e => "<li>" + e.Description + "</li>"); return(new ResultVM { Status = Status.Error, Message = "Invalid data", Data = string.Join("", resultErrors) }); } var userDb = await _userManager.FindByEmailAsync(associate.AssociateEmail); if (userDb != null) { // Rule #5 if (!userDb.EmailConfirmed) { return(new ResultVM { Status = Status.Error, Message = "Invalid data", Data = $"<li>Associated account (<i>{associate.AssociateEmail}</i>) hasn't been confirmed yet.</li><li>Confirm the account and try again</li>" }); } // Rule #4 var token = await _userManager.GenerateEmailConfirmationTokenAsync(userDb); var callbackUrl = Url.Action("ConfirmExternalProvider", "Account", values: new { userId = userDb.Id, code = token, loginProvider = associate.LoginProvider, providerDisplayName = associate.LoginProvider, providerKey = associate.ProviderKey }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(userDb.Email, $"Confirm {associate.ProviderDisplayName} external login", $"Please confirm association of your {associate.ProviderDisplayName} account by clicking <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>here</a>."); return(new ResultVM { Status = Status.Success, Message = "External account association is pending. Please check your email" }); } return(new ResultVM { Status = Status.Error, Message = "Invalid data", Data = $"<li>User with email {associate.AssociateEmail} not found</li>" }); }
public async Task <ResultViewModel> Associate([FromBody] AssociateViewModel model) { if (!model.associateExistingAccount) { var user = mapper.Map <AppUser>(model); var createUserResult = await loginService.CreateUserWithoutPassword(user); if (createUserResult.Succeeded) { if (model.Location == null) { return new ResultViewModel { Status = Status.Error, Message = $"user location cannot be null", } } ; var userId = (await loginService.FindByEmailAsync(user.Email)).Id; var cm = new Customer { IdentityId = userId, Location = model.Location }; loginService.CreateCustomer(cm); createUserResult = await loginService.AddLoginAsync(user, new ExternalLoginInfo(null, model.LoginProvider, model.ProviderKey, model.ProviderDisplayName)); if (createUserResult.Succeeded) { user.EmailConfirmed = true; await loginService.UpdateUser(user); var token = await jwtService.GetJwtToken(user); return(new ResultViewModel { Status = Status.Success, Message = $"{user.UserName} has been created successfully", Data = token }); } } var resultErrors = createUserResult.Errors.Select(e => "error description:" + e.Description); return(new ResultViewModel { Status = Status.Error, Message = "Invalid data", Data = string.Join("", resultErrors) }); } var userEntity = await loginService.FindByEmailAsync(model.AssociateEmail); if (userEntity != null) { if (!userEntity.EmailConfirmed) { return(new ResultViewModel { Status = Status.Error, Message = "Invalid data", Data = $"Associated account {model.AssociateEmail} hasn't been confirmed yet. " + "Confirm the account and try again" }); } var token = await loginService.GenerateEmailConfirmationTokenAsync(userEntity); var callbackUrl = Url.Action("ConfirmExternalProvider", "Account", values: new { userId = userEntity.Id, code = token, loginProvider = model.LoginProvider, providerDisplayName = model.ProviderDisplayName, providerKey = model.ProviderKey }, protocol: HttpContext.Request.Scheme); await emailService.SendEmailAsync(userEntity.Email, $"Confirm {model.ProviderDisplayName} external login", $"Please confirm association of your {model.ProviderDisplayName} " + $"account by clicking <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>here</a>"); return(new ResultViewModel { Status = Status.Success, Message = "External account association is pending. Please check your email" }); } return(new ResultViewModel { Status = Status.Error, Message = "Invalid data", Data = $"User with email {model.AssociateEmail} not found" }); } }
private void LoadMaterialTemplate(int templateId) { var supportService = new SupportService(User); var service = new MaterialService(User); var list = service.GetRDEMaterial(new[] { templateId }); if (list != null && list.Count > 0) { _materialTemplate = new RDEMaterialViewModel(list[0]); _materialTemplate.Traits = supportService.GetTraits(TraitCategoryType.Material.ToString(), _materialTemplate.MaterialID); // need to get associates and subparts... var subparts = service.GetMaterialParts(templateId); var associates = supportService.GetAssociates(TraitCategoryType.Material.ToString(), templateId); foreach (Associate assoc in associates) { var vm = new AssociateViewModel(assoc); _materialTemplate.Associates.Add(vm); } foreach (MaterialPart part in subparts) { var vm = new MaterialPartViewModel(part); _materialTemplate.SubParts.Add(vm); } } if (_materialTemplate != null) { mnuSetMaterialTemplate.Header = String.Format("Set _Material Template ({0}) ...", _materialTemplate.MaterialName); Config.SetProfile(User, ConfigMaterialTemplateId, templateId); } else { mnuSetMaterialTemplate.Header = "Set _Material Template..."; Config.SetProfile(User, ConfigMaterialTemplateId, -1); } }
private RDESiteViewModel BuildModel(int objectId, SiteExplorerNodeType objectType) { var service = new MaterialService(User); var supportService = new SupportService(User); RDESiteViewModel root = null; List<RDEMaterial> material; if (objectId < 0) { root = CreateSiteViewModel(new RDESite { LocalType=0 }); root.Locked = false; RegisterPendingChange(new InsertRDESiteCommand(root.Model)); var siteVisit = AddNewSiteVisit(root); AddNewMaterial(siteVisit); return root; } switch (objectType) { case SiteExplorerNodeType.Site: var sites = service.GetRDESites(new[] { objectId }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var siteVisits = service.GetRDESiteVisits(new[] {root.SiteID}, RDEObjectType.Site); var idList = new List<Int32>(); // This collection will keep track of every site visit id for later use... root.SiteVisits = new ObservableCollection<ViewModelBase>(siteVisits.ConvertAll(sv => { var vm = CreateSiteVisitViewModel(sv, root); idList.Add(vm.SiteVisitID); return vm; })); // This service call gets all the material for all site visits, saving multiple round trips to the database material = service.GetRDEMaterial(idList.ToArray(), RDEObjectType.SiteVisit); // But now we have to attach the material to the right visit... foreach (RDESiteVisitViewModel sv in root.SiteVisits) { // select out which material belongs to the current visit... RDESiteVisitViewModel sv1 = sv; var selected = material.Where(m => m.SiteVisitID == sv1.SiteVisitID); // create the material view models and attach to the visit. sv.Material = CreateMaterialViewModels(selected, sv); } } break; case SiteExplorerNodeType.SiteVisit: var visits = service.GetRDESiteVisits(new[] { objectId }); if (visits.Count > 0) { // get the site ... sites = service.GetRDESites(new[] { visits[0].SiteID }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var visitModel = CreateSiteVisitViewModel(visits[0], root); // get the material... material = service.GetRDEMaterial(new[] { visitModel.SiteVisitID }, RDEObjectType.SiteVisit); CreateMaterialViewModels(material, visitModel); } } break; case SiteExplorerNodeType.Material: material = service.GetRDEMaterial(new[] { objectId }); if (material.Count > 0) { var m = material[0]; // Get the Visit... visits = service.GetRDESiteVisits(new[] { m.SiteVisitID }); if (visits.Count > 0) { // Get the site... sites = service.GetRDESites(new[] { visits[0].SiteID }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var siteVisit = CreateSiteVisitViewModel(visits[0], root); CreateMaterialViewModels(material, siteVisit); } } } break; } if (root != null) { // Get a single list of all the material view models loaded... var materialList = new List<RDEMaterialViewModel>(); root.SiteVisits.ForEach(vm => { var sv = vm as RDESiteVisitViewModel; if (sv != null) { sv.Material.ForEach(vm2 => { var m = vm2 as RDEMaterialViewModel; materialList.Add(m); }); } }); var materialIds = materialList.Select(m => m.MaterialID).ToArray(); // for the material id list we can extract all the subparts in one round trip... var subparts = service.GetMaterialParts(materialIds); // and associates as well. This means we only need one pass through the material list in order to // hook up subordinate records var associates = supportService.GetAssociates(TraitCategoryType.Material.ToString(), materialIds); // But we have to hook them back up to the right material. foreach (RDEMaterialViewModel m in materialList) { var mlocal = m; var selectedSubParts = subparts.Where(part => part.MaterialID == mlocal.MaterialID); m.SubParts = new ObservableCollection<ViewModelBase>(selectedSubParts.Select(part => { var vm = new MaterialPartViewModel(part) { Locked = mlocal.Locked }; vm.DataChanged += SubPartDataChanged; return vm; })); RDEMaterialViewModel m1 = m; var selectedAssociates = associates.Where(assoc => assoc.FromIntraCatID == m1.MaterialID || assoc.ToIntraCatID == m1.MaterialID); m.Associates = new ObservableCollection<ViewModelBase>(selectedAssociates.Select(assoc => { var vm = new AssociateViewModel(assoc); vm.DataChanged += AssociateDataChanged; return vm; })); } } return root; }
private RDEMaterialViewModel AddNewMaterial(RDESiteVisitViewModel siteVisit) { if (siteVisit != null) { // create the new material... List<Trait> traits; List<Associate> associates; List<MaterialPart> subparts; var material = CreateNewMaterial(out traits, out associates, out subparts); var materialViewModel = new RDEMaterialViewModel(material); RegisterPendingChange(new InsertRDEMaterialCommand(material, siteVisit.Model)); RegisterUniquePendingChange(new UpdateRDEMaterialCommand(material) { SuccessAction = () => { materialViewModel.MaterialName = material.MaterialName; } }); if (traits != null && traits.Count > 0) { foreach (Trait t in traits) { materialViewModel.Traits.Add(t); RegisterPendingChange(new UpdateTraitDatabaseCommand(t, materialViewModel)); } } if (associates != null && associates.Count > 0) { foreach (Associate a in associates) { var vm = new AssociateViewModel(a); vm.DataChanged += AssociateDataChanged; materialViewModel.Associates.Add(vm); RegisterPendingChange(new InsertAssociateCommand(a, materialViewModel)); } } if (subparts != null && subparts.Count > 0) { foreach (MaterialPart subpart in subparts) { var vm = new MaterialPartViewModel(subpart); vm.DataChanged +=SubPartDataChanged; materialViewModel.SubParts.Add(vm); RegisterPendingChange(new InsertMaterialPartCommand(subpart, materialViewModel)); } } else { // Add one subpart... var subpart = new MaterialPartViewModel(new MaterialPart()) {MaterialPartID = -1, PartName = "<New>"}; materialViewModel.SubParts.Add(subpart); RegisterPendingChange(new InsertMaterialPartCommand(subpart.Model, materialViewModel)); } materialViewModel.SiteVisit = siteVisit; materialViewModel.SiteVisitID = siteVisit.SiteVisitID; siteVisit.Material.Add(materialViewModel); materialViewModel.DataChanged +=MaterialViewModelDataChanged; return materialViewModel; } return null; }
public string GetAccessToken(AssociateViewModel request) { return(AuthService.GenerateJSONWebToken(request)); }
public bool UsePestHostControl(AssociateViewModel associate) { if (associate != null && Preferences.UseSimplifiedAssociates.Value) { // New associate, or the relationships haven't been set yet - we can use the pest/host control in this case... if (string.IsNullOrWhiteSpace(associate.RelationFromTo) && string.IsNullOrWhiteSpace(associate.RelationToFrom)) { return true; } // Otherwise make sure the associate relationships are either Pest or Host only if (string.IsNullOrWhiteSpace(associate.RelationFromTo) || string.IsNullOrWhiteSpace(associate.RelationToFrom)) { return false; } if (!associate.RelationFromTo.Equals("pest", StringComparison.CurrentCultureIgnoreCase) && !associate.RelationFromTo.Equals("host", StringComparison.CurrentCultureIgnoreCase)) { return false; } if (!associate.RelationToFrom.Equals("pest", StringComparison.CurrentCultureIgnoreCase) && !associate.RelationToFrom.Equals("host", StringComparison.CurrentCultureIgnoreCase)) { return false; } return true; } return false; }
public void CreateSummaryOfIds(AssociateViewModel associateViewModel) { associateViewModel.SpecializationSummary = (associateViewModel.Specializations.Count > 0) ? string.Join(",", associateViewModel.specializationIds) : "Not specified"; }
public List <Specialization> GetSpecializaions(AssociateViewModel associateViewModel) { List <Specialization> listSpecialization = amsContext.Specializations.Where(speclztn => associateViewModel.specializationIds.Contains(speclztn.SpecializationId)).ToList(); return(listSpecialization); }
public AssociateHome() { InitializeComponent(); BindingContext = new AssociateViewModel(this); }
public ViewModelBase AddNewItem(out DatabaseCommand addAction) { var model = new Associate(); model.AssociateID = -1; model.FromIntraCatID = Owner.ObjectID.Value; model.FromCategory = Category.ToString(); model.Direction = "FromTo"; var viewModel = new AssociateViewModel(model); addAction = new InsertAssociateCommand(model, Owner); return viewModel; }