public UserCompanyShopViewModel InsertUserToCompanyShop(string userId, int companyId, int shopId, string createdBy) { var query = $"EXEC InsertUserToCompanyShop '{userId}', '{companyId}', '{shopId}', '{createdBy}', '{0}', '{DateTime.UtcNow}'; "; UserCompanyShopViewModel userCompanyShopViewModel = _context.UserCompanyShopViewModel.FromSql(query).FirstOrDefault(); return(userCompanyShopViewModel); }
public async Task <object> Create([FromBody] CreateUserViewModel createUserViewModel) { try { var user = new ApplicationUser { UserName = createUserViewModel.Email, Email = createUserViewModel.Email, FirstName = createUserViewModel.FirstName, LastName = createUserViewModel.LastName, IsActive = true, IsCompanySelected = true, IsShopSelected = true, }; string password = GenerateRandomPassword(); var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, createUserViewModel.UserRole); UserCompanyShopViewModel userCompanyShopViewModel = _userRepository.InsertUserToCompanyShop(user.Id, createUserViewModel.CompanyId, createUserViewModel.ShopId, createUserViewModel.CreatedBy); await SendEmailAsync(userCompanyShopViewModel.Email, password, userCompanyShopViewModel.UserName, userCompanyShopViewModel.CompanyName, userCompanyShopViewModel.ShopName); return(new SingleResponse <ApplicationUser> { Message = "User created successfully", DidError = false, ErrorMessage = string.Empty, Token = string.Empty, Model = user }); } else { return(new SingleResponse <ApplicationUser> { Message = result.Errors.FirstOrDefault().Description, DidError = true, ErrorMessage = string.Empty, Token = string.Empty, Model = user }); } } catch (Exception ex) { return(new SingleResponse <ApplicationUser> { Message = string.Empty, DidError = true, ErrorMessage = ex.Message, Token = string.Empty, Model = null }); } }