public ActionResult AddEmployee(AuthEmployee emp) { try { using (sithar_dbEntities1 db = new sithar_dbEntities1()) { db.AuthEmployees.Add(emp); db.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Initial")); } catch { return(View()); } }
public ActionResult UpdateEmployee(int id, AuthEmployee emp) { try { using (sithar_dbEntities1 db = new sithar_dbEntities1()) { db.Entry(emp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } // TODO: Add update logic here return(RedirectToAction("Initial")); } catch { return(View()); } }
public ActionResult DeleteEmployee(int id, FormCollection collection) { try { using (sithar_dbEntities1 db = new sithar_dbEntities1()) { AuthEmployee emp = db.AuthEmployees.Where(x => x.AuthEmployeeId == id).FirstOrDefault(); db.AuthEmployees.Remove(emp); db.SaveChanges(); } // TODO: Add delete logic here return(RedirectToAction("Initial")); } catch { return(View()); } }
public async Task <IActionResult> Login(AuthEmployee userForLogin) { var employeeDb = await _logic.Login(userForLogin.Username.ToLower(), userForLogin.Password.ToLower()); if (employeeDb == null) { return(Unauthorized()); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, employeeDb.EmployeeID.ToString()), new Claim(ClaimTypes.Name, employeeDb.Username) }; var key = new SymmetricSecurityKey(Encoding.UTF8. GetBytes(_config.GetSection("AppSettings:Token").Value)); var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), Expires = DateTime.Now.AddDays(1), SigningCredentials = credentials }; var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateToken(tokenDescriptor); return(Ok(new { token = tokenHandler.WriteToken(token), employee = employeeDb })); }