public async Task <IActionResult> PutEmployeeOwner([FromBody] EmployeeOwner employeeOwner, [FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.EmployeeOwners on bb.id equals cc.id_user where aa.access == token select cc).FirstOrDefault(); _context.Entry(user).State = EntityState.Modified; user.phone = employeeOwner.phone; user.lastname = employeeOwner.lastname; user.firstname = employeeOwner.firstname; user.email = user.email; try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, ex.Message))); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, user, null))); }
public bool CheckFilledStaff(EmployeeOwner account) { if (account.email == null) { return(false); } if (account.firstname == null) { return(false); } if (account.phone == null) { return(false); } return(true); }
public async Task <JsonResult> PostEmployeeOwner([FromBody] EmployeeOwner employeeOwner, [FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.Accounts on bb.id equals cc.id_user where aa.access == token select cc; var usercheck = user.FirstOrDefault(); var check = await _context.Auths.Where(x => (x.email == employeeOwner.email && employeeOwner.email != null) || (x.Phone == employeeOwner.phone && employeeOwner.phone != null)).FirstOrDefaultAsync(); if (check != null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, "Такой пользователь уже есть"))); } else { if (employeeOwner.phone.StartsWith('7')) { employeeOwner.phone = employeeOwner.phone.Substring(1).Replace("(", "").Replace(")", ""); } ServicesModel.Models.Auth.Auth auth = new ServicesModel.Models.Auth.Auth { email = employeeOwner.email, Phone = employeeOwner.phone, data_add = DateTime.Now, password = "******", role = "staff", UserName = employeeOwner.email, last_visit = DateTime.Now }; await _context.Auths.AddAsync(auth); //var result = await _manager.CreateAsync(auth, auth.password); //if (result.Succeeded) //{ // var currentUser = await _manager.FindByNameAsync(auth.email); // var roleresult = _manager.AddToRoleAsync(auth, auth.role); //} await _context.SaveChangesAsync(); // var id = await _context.Auths.Where(x => x.email == auth.email).FirstOrDefaultAsync(); //await _context.Auths.AddAsync(auth); string link = _auth.GenerateRefreshToken().Substring(0, 9); employeeOwner.link = link; employeeOwner.id_user = auth.id; employeeOwner.id_owner = usercheck.id; employeeOwner.date_add = DateTime.Now; await _context.EmployeeOwners.AddAsync(employeeOwner); await _context.SaveChangesAsync(); // var account = await _context.EmployeeOwners.Where(x => x.id_user == id.id).FirstOrDefaultAsync(); await _auth.ConfirmStaff(link, auth.email); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.Created, employeeOwner, null))); } }