public ActionResult UserLogin(user User) { try { if (ModelState.IsValid) { using (RegisterEntities info = new RegisterEntities()) { var CurrentUser = info.users.Where(a => a.userId.Equals(User.userId) && a.password.Equals(User.password)).FirstOrDefault(); if (CurrentUser != null) { Session["userId"] = User.userId; TempData["currentUser"] = User.userId; var holdUser = User.userId; return(RedirectToAction("DashBoard")); } else { Response.Write("<script>alert('Invalid username or password')</script>"); } } } } catch (Exception ex) { Response.Write(ex.Message); } return(View()); }
public ActionResult HtmlHelperExample() { RegisterEntities db = new RegisterEntities(); ViewBag.Register = new SelectList(db.Registers, "Id", "Name", "Select User"); return(View()); }
/// <summary> /// Queries a single Employee /// </summary> /// <param name="id">Employee</param> /// <returns>Single Employer including the Employer.</returns> public Employee Get(int id) { using (var db = new RegisterEntities()) { return(db.Employees.Find(id)); } }
public ActionResult GetData() { using (RegisterEntities db = new RegisterEntities()) { List <user> userList = db.users.ToList(); return(Json(new { data = userList }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Register(Registration model) { using (var context = new RegisterEntities()) { Registration registration = context.Registration.Add(model); context.SaveChanges(); } return(RedirectToAction("Login")); }
/// <summary> /// Queries a single Employer /// </summary> /// <param name="id">Employer</param> /// <returns>Single Employer including all Employees and SubContractors.</returns> public Employer Get(int id) { using (var db = new RegisterEntities()) { var employer = db.Employers .Single(e => e.Id == id); employer.SubContractors = employer.SubContractors.Where(s => s.Deleted != true).ToList(); employer.Employees = employer.Employees.Where(e => e.Deleted != true).ToList(); return(employer); } }
public object GetSelectList(int?id) { using (var db = new RegisterEntities()) { if (id.HasValue) { return(new SelectList(db.Employers.ToList(), "Id", "Name", id.Value)); } else { return(new SelectList(db.Employers.ToList(), "Id", "Name")); } } }
/// <summary> /// Soft deletes a single Employee /// </summary> /// <param name="id">Employee</param> /// <returns>True if successful.</returns> public bool Delete(int id) { using (var db = new RegisterEntities()) { var employee = db.Employees.Find(id); if (employee != null) { employee.Deleted = true; db.SaveChanges(); return(true); } } return(false); }
/// <summary> /// Queries all sub-contractors /// </summary> /// <param name="id">General Contractor</param> /// <returns>Collection of sub-contractors.</returns> public IEnumerable <Employer> ListSubContractors(int id) { using (var db = new RegisterEntities()) { var subContractors = db.Employers .Single(e => e.Id == id) .SubContractors.Where(s => s.Deleted != true); foreach (var subContractor in subContractors) { subContractor.SubContractors = subContractor.SubContractors.Where(s => s.Deleted != true).ToList(); subContractor.Employees = subContractor.Employees.Where(e => e.Deleted != true).ToList(); } return(subContractors); } }
/// <summary> /// By defauld queries all independent employers. /// </summary> /// <param name="independent"></param> /// <returns>Collection of employers including their employees & sub-contractors.</returns> public IEnumerable <Employer> List(bool independent = true) { using (var db = new RegisterEntities()) { var employers = db.Employers .Where(e => e.Deleted != true) .Where(e => e.GeneralContractor == null || !independent); foreach (var employer in employers) { employer.SubContractors = employer.SubContractors.Where(s => s.Deleted != true).ToList(); employer.Employees = employer.Employees.Where(e => e.Deleted != true).ToList(); } return(employers.ToList()); } }
public bool Modify(Employee employee) { using (var db = new RegisterEntities()) { try { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } } }
public bool Add(Employee employee) { using (var db = new RegisterEntities()) { try { db.Employees.Add(employee); db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } } }
public ActionResult Login(Models.Login model) { using (var context = new RegisterEntities()) { bool isvalid = context.Registration.Any(x => x.Email == model.Email && x.Password == model.Password); if (isvalid) { FormsAuthentication.SetAuthCookie(model.Email, false); return(RedirectToAction("Page", "Home")); } else { ModelState.AddModelError("", "Invalid Data"); return(View()); } } }