Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [Route("CreateUser/{UserId}/{jobRouterLogin}")]
- public HttpResponseMessage AddNewUser(int userId, string jobRouterLogin)
- {
- if (HttpContext.Current.Request.IsLocal)
- {
- try
- {
- using (var optimaDbContext = new OptimaDbContext())
- {
- var user = optimaDbContext.Employees.FirstOrDefault(n => n.ID == userId);
- if (user == null)
- {
- return new HttpResponseMessage(HttpStatusCode.NotFound);
- }
- var userDatabase = optimaDbContext.Clients
- .FirstOrDefault(n => n.Baza_danych == user.DP_NazwaBazyKlienta).Nazwa_firmy;
- var company = dbContext.Companies.FirstOrDefault(n => n.Name == userDatabase);
- if (company == null)
- {
- company = dbContext.Companies.Add(new Company()
- {
- Name = userDatabase
- });
- }
- string newUserPassword = HashHelper.ComputeSha256("userPassword");
- dbContext.Users.Add(new User()
- {
- CompanyId = company.CompanyId,
- Password = newUserPassword,
- Username = jobRouterLogin,
- UserId = userId
- });
- dbContext.SaveChanges();
- return new HttpResponseMessage(HttpStatusCode.OK);
- }
- }
- catch
- {
- return new HttpResponseMessage(HttpStatusCode.NotModified);
- }
- }
- else
- {
- return new HttpResponseMessage(HttpStatusCode.Forbidden);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement