コード例 #1
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 (MvcProject_Raihan01Entities db = new MvcProject_Raihan01Entities())
         {
             if (emp.EmployeeID == 0)
             {
                 db.Employees.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, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #2
0
        public ActionResult Create([Bind(Include = "CustomerID,Name,Age,DateOfBirth,Address,Phone,Email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "PublisherId,Name,CellPhoneNo,Email,PublishDate")] Publisher publisher)
        {
            if (ModelState.IsValid)
            {
                db.Publishers.Add(publisher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(publisher));
        }
コード例 #4
0
        public ActionResult Create(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                var student = Mapper.Map <Student>(studentVM);
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(studentVM));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "BookDetailsID,BookName,PublisherId,PurchaseDate,ReturnDate,BookPrice,ServiceCharge,DeleveryCharge,Total")] BookDetail bookDetail)
        {
            if (ModelState.IsValid)
            {
                db.BookDetails.Add(bookDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PublisherId = new SelectList(db.Publishers, "PublisherId", "Name", bookDetail.PublisherId);
            return(View(bookDetail));
        }
コード例 #6
0
 public ActionResult Delete(int id)
 {
     using (MvcProject_Raihan01Entities db = new MvcProject_Raihan01Entities())
     {
         Auther emp = db.Authers.Where(x => x.AutherID == id).FirstOrDefault <Auther>();
         db.Authers.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully", JsonRequestBehavior.AllowGet }));
     }
 }
コード例 #7
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (MvcProject_Raihan01Entities db = new MvcProject_Raihan01Entities())
         {
             Employee emp = db.Employees.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>();
             db.Employees.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, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #8
0
 public JsonResult Add(EmployeeInfromation user)
 {
     _context.EmployeeInfromations.Add(user);
     _context.SaveChanges();
     return(Json(JsonRequestBehavior.AllowGet));
 }