Пример #1
0
 public ActionResult <CompanyVM> PostCompany(CompanyVM companyVM)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var userId = _userManager.GetUserId(User);
             if (_companyRepo.GetUserCompanyId(userId).Item1.HasValue)
             {
                 return(BadRequest(new { message = "Company already exist" }));
             }
             var result = _companyRepo.AddCompany(companyVM, userId);
             return(Ok(result));
         }
         catch (Exception e)
         {
             return(StatusCode(500, new { message = e.Message }));
         }
     }
     return(BadRequest());
 }
Пример #2
0
        private ActionResult BuildLoginOkResponse(SystemUser user)
        {
            var    tokenString = GenerateJSONWebToken(user);
            var    userRole    = _userRepo.GetUserRoleName(user.Id);
            int?   profileId   = null;
            string userName    = "******";

            if (userRole?.ToLower() == "company")
            {
                var companyUser = _companyRepo.GetUserCompanyId(user.Id);
                profileId = companyUser.Item1;
                userName  = companyUser.Item2;
            }
            else if (userRole?.ToLower() == "labourer")
            {
                var labourer = _labourerRepo.GetUserLabourerId(user.Id);
                profileId = labourer.Item1;
                userName  = labourer.Item2;
            }

            return(Ok(new { token = tokenString, username = userName, role = userRole?.ToLower(), profileId = profileId, status = "OK" }));
        }