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));
     }
 }
 public ActionResult Edit([Bind(Include = "CustomerID,Name,Age,DateOfBirth,Address,Phone,Email")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
 public ActionResult Edit([Bind(Include = "PublisherId,Name,CellPhoneNo,Email,PublishDate")] Publisher publisher)
 {
     if (ModelState.IsValid)
     {
         db.Entry(publisher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(publisher));
 }
예제 #4
0
 public ActionResult Edit(StudentVM studentVM)
 {
     if (ModelState.IsValid)
     {
         var student = Mapper.Map <Student>(studentVM);
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(studentVM));
 }
예제 #5
0
 public ActionResult Edit([Bind(Include = "BookDetailsID,BookName,PublisherId,PurchaseDate,ReturnDate,BookPrice,ServiceCharge,DeleveryCharge,Total")] BookDetail bookDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PublisherId = new SelectList(db.Publishers, "PublisherId", "Name", bookDetail.PublisherId);
     return(View(bookDetail));
 }