public IHttpActionResult PutCar(int id, Car car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != car.CarId) { return(BadRequest()); } db.Entry(car).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "id,year,make,model,type,horsepower,cylinders")] Car car) { if (ModelState.IsValid) { db.Cars.Add(car); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(car)); }
public ActionResult UserSelectedCar(string possibleCars) { if (!ModelState.IsValid) { return(View()); } int id = -1; id = int.Parse(possibleCars); string thisUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); db.SetUnavailable(id, thisUserId); db.SaveChanges(); return(RedirectToAction("Cars", "Car")); }
public void DeleteCar(int ID) { CarsEntities ORM = new CarsEntities(); Car found = ORM.Cars.Find(ID); ORM.Cars.Remove(found); ORM.SaveChanges(); }
public void EditCar(Car editCar) { CarsEntities ORM = new CarsEntities(); Car found = ORM.Cars.Find(editCar.CarID); found.Color = editCar.Color; found.Make = editCar.Model; found.Model = editCar.Model; ORM.Entry(found).State = System.Data.Entity.EntityState.Modified; //let them know it changed ORM.SaveChanges(); }
public ActionResult AddNewCar(Car newCar) { database.Cars.Add(newCar); database.SaveChanges(); return(View("Index")); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { _myDataBase.SaveChanges(); }
public JsonResult Register(User user, List <HttpPostedFileBase> Photos) { if (string.IsNullOrEmpty(user.Fullname) || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.Email) || Photos == null) { return(Json(new { status = 403, message = "Ad Soyad,E-poçt,Şifrə və ya Şəkil boş ola bilməz" }, JsonRequestBehavior.AllowGet)); } if (db.Users.FirstOrDefault(u => u.Email == user.Email) != null) { return(Json(new { status = 401, message = "Bu e-poçt ünvanı artıq istifadə edilmişdir" }, JsonRequestBehavior.AllowGet)); } foreach (var photos in Photos) { if ((photos.ContentLength / 1024) / 1024 > 1) { return(Json(new { status = 406, message = "You can not upload images larger than 1M" }, JsonRequestBehavior.AllowGet)); } if (photos.ContentType != "image/jpeg" && photos.ContentType != "image/png" && photos.ContentType != "image/gif") { return(Json(new { status = 407, message = "You can only upload images" }, JsonRequestBehavior.AllowGet)); } filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + photos.FileName; string createFile = Path.Combine(Server.MapPath("~/Uploads"), filename); photos.SaveAs(createFile); } user.Photo = filename; user.Password = Crypto.HashPassword(user.Password); db.Users.Add(user); db.SaveChanges(); Thread.Sleep(3000); return(Json(new { status = 200, message = "Siz artiq qeydiyyatdan keçdiniz" }, JsonRequestBehavior.AllowGet)); }
public void Create(T item) { Context.Set <T>().Add(item); Context.SaveChanges(); }