public async Task <ActionResult <LoginDTO> > Login(string credential, string loginMethod) { if (string.IsNullOrEmpty(credential)) { return(BadRequest()); } ApplicationUser user; switch (loginMethod) { case "phone": var phonenumber = credential.Trim(); user = _context.Set <ApplicationUser>().FirstOrDefault(u => u.PhoneNumber == phonenumber); break; case "aad": user = await _userManager.FindByLoginAsync("Microsoft", credential); break; default: user = null; break; } if (user == null) { return(NotFound(new { message = "No user with this phone number has been found" })); } await _signInManager.SignInAsync(user, true); var response = new LoginDTO { Id = user.Id, Email = user.Email, Alias = user.Alias, UserName = user.UserName, PhoneNumber = user.PhoneNumber, Language = user.Language, Roles = await _userManager.GetRolesAsync(user), Token = await GenerateJwtToken(credential, user) }; return(response); }
public async Task <ActionResult <IEnumerable <Opportunity> > > GetOpportunitiesByLeadAndOwner (string leadFirstName, string leadLastName, string ownerPhoneNumber) { if (string.IsNullOrEmpty(leadFirstName) || string.IsNullOrEmpty(leadLastName) || string.IsNullOrEmpty(ownerPhoneNumber)) { return(BadRequest()); } //Searching the lead var lead = await _leadDao.GetLeadByName(leadFirstName, leadLastName); if (lead == null) { return(NotFound("lead-not-found")); } //Searching the owner var owner = _context.Set <ApplicationUser>().FirstOrDefault(u => u.PhoneNumber == ownerPhoneNumber); if (owner == null) { return(NotFound("owner-not-found")); } var opportunities = await _context.Opportunities .Where(o => o.Lead == lead && o.Owner == owner) .Include(o => o.Owner) .Include(o => o.Product) .Include(o => o.Lead) .ToListAsync(); if (opportunities == null || opportunities.Count == 0) { return(NotFound("opportunities-not-found")); } return(opportunities); }
public async Task <ActionResult <IEnumerable <Opportunity> > > GetOpportunitiesByCompanyAndOwner (string companyName, string ownerPhoneNumber) { if (string.IsNullOrEmpty(companyName) || string.IsNullOrEmpty(ownerPhoneNumber)) { return(BadRequest()); } //Searching the company var company = await _companyDAO.GetCompanyByName(companyName); if (company == null) { return(NotFound("company-not-found")); } //Searching the owner var owner = _context.Set <ApplicationUser>().FirstOrDefault(u => u.PhoneNumber == ownerPhoneNumber); if (owner == null) { return(NotFound("owner-not-found")); } //Searching the opportunities var opportunities = await _context.Opportunities .Include(o => o.Owner) .Include(o => o.Product) .Include(o => o.Lead) .Where(o => o.Lead.Company == company && o.Owner == owner) .ToListAsync(); if (opportunities == null || opportunities.Count == 0) { return(NotFound("opportunities-not-found")); } return(Ok(opportunities)); }
public async Task <IActionResult> Index() { return(View(await _context.Set <ApplicationUser>().ToListAsync())); }