Beispiel #1
0
        public ActionResult Index(EmployeeVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                EmployeeTbl tbl = new EmployeeTbl();
                tbl.EmployeeName     = model.EmployeeName;
                tbl.PresentAddress   = model.PresentAddress;
                tbl.PermanentAddress = model.PermanentAddress;
                tbl.LocationId       = model.LocationId;
                tbl.PositionId       = model.PositionId;
                tbl.Gender           = model.Gender;
                tbl.Phone            = model.PhoneNumber;
                tbl.IsUserOfSystem   = model.IsUserOfSystem;
                tbl.DateOfBirth      = model.DateOfBirth;
                tbl.JoiningDate      = model.JoiningDate;
                tbl.Salary           = model.Salary;
                //tbl.MaritalStatus = model.MaritalStatus;
                int id = model.EmployeeId;

                db.EmployeeTbls.Add(tbl);
                db.SaveChanges();
            }

            TempData["SM"] = "You Have Added A Employee Information";

            return(RedirectToAction("Index"));
        }
 public PageRegister()
 {
     InitializeComponent();
     emp = new EmployeeTbl();
     this.DataContext = emp;
     LoadAll();
 }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeTbl employeeTbl = db.EmployeeTbls.Find(id);

            db.EmployeeTbls.Remove(employeeTbl);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "empId,empName,empSal,deptId")] EmployeeTbl employeeTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeeTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.deptId = new SelectList(db.DepartmentTbls, "DeptId", "DeptName", employeeTbl.deptId);
     return(View(employeeTbl));
 }
Beispiel #5
0
        public ActionResult DeleteInfo(int id)
        {
            using (Db db = new Db())
            {
                EmployeeTbl tbl = db.EmployeeTbls.Find(id);
                db.EmployeeTbls.Remove(tbl);
                db.SaveChanges();
            }

            return(RedirectToAction("Info"));
        }
Beispiel #6
0
        public ActionResult AddOrEdit(int id = 0)
        {
            EmployeeTbl emp = new EmployeeTbl();

            if (id != 0)
            {
                using (EmployeesEntities db = new EmployeesEntities())
                {
                    emp = db.EmployeeTbls.Where(x => x.EmployeeId == id).FirstOrDefault <EmployeeTbl>();
                }
            }
            return(View(emp));
        }
Beispiel #7
0
        // GET: EmployeeTbls/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeTbl employeeTbl = db.EmployeeTbls.Find(id);

            if (employeeTbl == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeTbl));
        }
Beispiel #8
0
        // GET: EmployeeTbls/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeTbl employeeTbl = db.EmployeeTbls.Find(id);

            if (employeeTbl == null)
            {
                return(HttpNotFound());
            }
            ViewBag.deptId = new SelectList(db.DepartmentTbls, "DeptId", "DeptName", employeeTbl.deptId);
            return(View(employeeTbl));
        }
Beispiel #9
0
        public ActionResult EditInfo(int id)
        {
            EmployeeVm  model;
            Db          db  = new Db();
            EmployeeTbl tbl = db.EmployeeTbls.Find(id);

            if (tbl == null)
            {
                return(Content("Information Not Found!"));
            }

            ViewBag.Location = new SelectList(db.LocationTbls, "LocationId", "LocationName");
            ViewBag.Position = new SelectList(db.PositionTbls, "PositionId", "PositionName");

            model = new EmployeeVm(tbl);

            return(View(model));
        }
Beispiel #10
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (EmployeesEntities db = new EmployeesEntities())
                {
                    EmployeeTbl emp = db.EmployeeTbls.Where(x => x.EmployeeId == id).FirstOrDefault <EmployeeTbl>();
                    db.EmployeeTbls.Remove(emp);
                    db.SaveChanges();
                }

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Deleted Successfully" },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = ex.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #11
0
        public ActionResult AddOrEdit(EmployeeTbl emp)
        {
            try
            {
                if (emp.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName);
                    string extention = Path.GetExtension(emp.ImageUpload.FileName);
                    fileName  = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                    emp.Image = "~/AppFiles/Images/" + fileName;
                    emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }

                using (EmployeesEntities db = new EmployeesEntities())
                {
                    if (emp.EmployeeId == 0)
                    {
                        db.EmployeeTbls.Add(emp);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Entry(emp).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Submitted Successfully" },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = ex.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }