public string Get(int id, [FromBody] Users2 value) { var loginUser = db.Users2.FromSql("SpLogin @us_id,@us_password", new SqlParameter("@us_id", id), new SqlParameter("@us_password", value.UsPassword)); Users2 user = new Users2(); foreach (var item in loginUser) { user.UsId = item.UsId; user.UsName = item.UsName; string userRole; if (user.UsId == 1) { userRole = "Admin"; } else { userRole = "Customer"; } return(AuthController.GenerateJSONWebToken(user.UsId, userRole)); } return("Invalid User"); }
public async Task <IActionResult> PutUser(int id, Users2 user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void btnSave_Click(object sender, EventArgs e) { if (rbEntity1.Checked) { var _users = _database.GetCollection <Users3>("users"); var user = new Users3 { }; user.Age = Convert.ToInt32(txtAge.Text); user.Name = txtName.Text; user.Location = txtLocation.Text; _users.Insert(user); var id = user.Id; } else if (rbEntity2.Checked) { var _users = _database.GetCollection <Users2>("users"); var user = new Users2 { }; user.Name = txtName.Text; user.Location = txtLocation.Text; _users.Insert(user); var id = user.Id; } else if (rbEntity3.Checked) { var _users = _database.GetCollection <Users1>("users"); var user = new Users1 { }; user.Age = Convert.ToInt32(txtAge.Text); user.Name = txtName.Text; _users.Insert(user); var id = user.Id; } MessageBox.Show("User with name " + txtName.Text + " created"); }
public ActionResult Register(Users2 users) { Users us = new Users(); AccomodationOwner accom = new AccomodationOwner(); Student stu = new Student(); if (ModelState.IsValid) { if (users.UsersType == "Student") { stu.University = "University of Witswatersrand"; } else { accom.phoneNumber = 0834979732; } us.name = users.name; us.password = users.password; us.username = users.username; db.Users.Add(us); try { db.SaveChanges(); if (stu.University == null) { Users d = db.Users.Where(c => c.username == users.username).FirstOrDefault(); accom.UsersId = d.Id; db.AccomodationOwner.Add(accom); db.SaveChanges(); } else { Users d = db.Users.Where(c => c.username == users.username).FirstOrDefault(); stu.UsersId = d.Id; db.Student.Add(stu); db.SaveChanges(); } } catch (Exception e) { e.ToString(); } } ViewBag.Message = "Wrong!!"; return(View()); }
public async Task <ActionResult <User> > PostUser(Users2 user) { var users2 = new Users2(); try { users2 = await _context.Users2.SingleOrDefaultAsync(u => u.Rfid_uid == user.Rfid_uid); } catch { } if (users2 == null) { _context.Users2.Add(user); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUser", new { id = user.Id }, user)); } else { users2.Created = user.Created; users2.Name = user.Name; users2.Rfid_uid = user.Rfid_uid; _context.Entry(users2).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetUser", new { id = user.Id }, user)); } }
public void Post([FromBody] Users2 value) { db.Database.ExecuteSqlCommand("SpSignUp @us_name,@us_password", new SqlParameter("@us_name", value.UsName), new SqlParameter("@us_password", value.UsPassword)); }