Esempio n. 1
0
 public JsonResult AddCarType(CarTypeValidation cartype, HttpPostedFileBase image)
 {
     if (image != null && image.ContentLength > 0)
     {
         //if supply image file save it to the server and save the path to the database
         cartype.Picture = Utilitys.GetRandomFileName("jpg");
         string _path = Path.Combine(Server.MapPath("~/Images"), cartype.Picture);
         image.SaveAs(_path);
     }
     using (CarTypeData db = new CarTypeData())
     {
         bool add = db.Add(cartype);
         return(Json(add));
     }
 }
Esempio n. 2
0
 public JsonResult UpdateCarType(CarTypeValidation cartype, HttpPostedFileBase image, int id)
 {
     //if supply image save to server
     if (image != null && image.ContentLength > 0)
     {
         if (string.IsNullOrEmpty(cartype.Picture))
         //if the car didnt had image before create new file name
         {
             cartype.Picture = Utilitys.GetRandomFileName("jpg");
         }
         string _path = Path.Combine(Server.MapPath("~/Images"), cartype.Picture);
         image.SaveAs(_path);
     }
     using (CarTypeData db = new CarTypeData())
     {
         bool update = db.Update(_cartype => _cartype.id == id, cartype);
         return(Json(update));
     }
 }