public ActionResult AddOrEdit(Employee emp)
        {
            try
            {
                if (emp.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName);
                    string extension = Path.GetExtension(emp.ImageUpload.FileName);
                    fileName      = fileName + DateTime.Now.ToString("yymmssff") + extension;
                    emp.ImagePath = "~/AppFiles/Images/" + fileName;
                    emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }

                using (jQueryAjaxDBEntities db = new jQueryAjaxDBEntities())
                {
                    if (emp.EmployeeID == 0)
                    {
                        db.Employees.Add(emp);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Entry(emp).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                //return RedirectToAction("ViewAll");
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("ViewAll"));
        }
Beispiel #2
0
        public ActionResult AddOrEdit(Employee emp)
        {
            try
            {
                if (emp.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName);
                    string extension = Path.GetExtension(emp.ImageUpload.FileName);
                    fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    emp.ImagePath = "~/AppFiles/Images/" + fileName;
                    emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }

                using (jQueryAjaxDBEntities ent = new jQueryAjaxDBEntities())
                {
                    if (emp.Id == 0)
                    {
                        ent.Employees.Add(emp);
                        ent.SaveChanges();
                    }
                    else
                    {
                        ent.Entry(emp).State = EntityState.Modified;
                        ent.SaveChanges();
                    }
                }
                return(Json(new { success = true, html = ViewToStringConverter.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (jQueryAjaxDBEntities ent = new jQueryAjaxDBEntities())
         {
             Employee emp = ent.Employees.Where(x => x.Id == id).FirstOrDefault <Employee>();
             ent.Employees.Remove(emp);
             ent.SaveChanges();
         }
         return(Json(new { success = true, html = ViewToStringConverter.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #4
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (jQueryAjaxDBEntities db = new jQueryAjaxDBEntities())
                {
                    Employee emp = db.Employee.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>();
                    db.Employee.Remove(emp);
                    db.SaveChanges();
                }

                return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Sikeres törlés." }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }