public async Task <IActionResult> Get() { try { AppUser user = _user.Users .Where(u => u.UserName == User.Identity.Name) .Include(u => u.Balance) .Include(u => u.Receipts).FirstOrDefault(); var roles = await _userManager.GetRolesAsync(user); foreach (var role in roles) { if (role == Helper.Roles.PrivateCustomer.ToString()) { PrivateCustomer customer = _privateContext.GetWithCamexId(user.CamexId); UserVm userVm = new UserVm { User = user, PrivateCustomer = customer, BusinessCustomer = null }; return(Ok(userVm)); } else if (role == Helper.Roles.BusinessCustomer.ToString()) { BusinessCustomer customer = _businesContext.GetWithCamexId(user.CamexId); UserVm userVm = new UserVm { User = user, PrivateCustomer = null, BusinessCustomer = customer }; return(Ok(userVm)); } } return(NotFound()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult Business(string id) { try { if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Messages = new Message[] { new Message { Lang_id = 1, MessageLang = "Model state isn't valid!" }, new Message { Lang_id = 2, MessageLang = "Состояние модели недействительно!" }, new Message { Lang_id = 3, MessageLang = "Model vəziyyəti etibarsızdır!" } } })); } AppUser appUser = _userDbContext.Users.Where(u => u.Id == id) .Include(u => u.City).ThenInclude(c => c.CityNameTranslates) .Include(u => u.Balance) .Include(u => u.Office).ThenInclude(o => o.OfficeNameTranlates).FirstOrDefault(); if (appUser == null) { return(StatusCode(StatusCodes.Status404NotFound)); } BusinessCustomer customer = _businessContext.GetWithCamexId(appUser.CamexId); if (customer == null) { return(StatusCode(StatusCodes.Status404NotFound)); } return(Ok( new BusinessUserAdmin { User = appUser, BusinessCustomer = customer })); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult GetUser() { string UserName = User.Identity.Name; List <string> Roles = User.FindAll(ClaimTypes.Role).Select(c => c.Value.ToString()).ToList(); AppUser user = _userDbContext.Users .Where(u => u.UserName == UserName) .Include(u => u.Balance) .FirstOrDefault(); foreach (string role in Roles) { if (role == Helper.Roles.BusinessCustomer.ToString()) { BusinessCustomer businessCustomer = _businessContext.GetWithCamexId(user.CamexId); UserNavVM userNav = new UserNavVM { CompanyName = businessCustomer.CompanyName, UserBalance = user.Balance.UserBalance, Roles = Roles, Image = user.Image }; return(Ok(userNav)); } else if (role == Helper.Roles.PrivateCustomer.ToString()) { PrivateCustomer privateCustomer = _privateContext.GetWithCamexId(user.CamexId); UserNavVM userNav = new UserNavVM { Name = privateCustomer.Name, Surname = privateCustomer.Surname, UserBalance = user.Balance.UserBalance, Roles = Roles, Image = user.Image }; return(Ok(userNav)); } } return(NotFound()); }