public static int Delete(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to delete tblRating deleteRow = (from dt in dc.tblRatings where dt.Id == id select dt).FirstOrDefault(); if (deleteRow != null) { dc.tblRatings.Remove(deleteRow); return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static bool Insert(Rating rating) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { // Make a new row tblRating newrow = new tblRating(); // Set the properties // Ternary Operator condition ? true : false newrow.Id = dc.tblRatings.Any() ? dc.tblRatings.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1 newrow.Description = rating.Description; // Do the Insert dc.tblRatings.Add(newrow); // Commit the insert dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public void LoadById() { try { using (DVDEntities dc = new DVDEntities()) { //Make sure that the ID is set and valid if (this.Id >= 0) { tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == this.Id); //Make sure that a rating was retrieved if (rating != null) { //Set the properties on this rating this.Description = rating.Description; } else { throw new Exception("No rating to load with this Id"); } } else { throw new Exception("Rating Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public static int Delete(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating deleterow = dc.tblRatings.FirstOrDefault(dt => dt.Id == id); if (deleterow != null) { // Remove the row dc.tblRatings.Remove(deleterow); // Commit/Save the changes return(dc.SaveChanges()); } else { throw new Exception("Row was not found."); } } } catch (Exception ex) { throw ex; } }
public static int Update(Rating rating) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblRating updateRow = (from dt in dc.tblRatings where dt.Id == rating.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.Description = rating.Description; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Update(Rating rating) { using (DVDCentralEntities dc = new DVDCentralEntities()) { try { tblRating updatedrow = dc.tblRatings.Where(dt => dt.Id == rating.Id).FirstOrDefault(); // Check to see if object exists if (rating != null) { // Update the proper fields updatedrow.Description = rating.Description; // Save and commit changes return(dc.SaveChanges()); } else { // throw an exception stating the row was not found throw new Exception("Row was not found."); } } catch (Exception ex) { throw ex; } } }
public static int Insert(Rating rating) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating tblRating = new tblRating(); tblRating.Description = rating.Description; //example of ternary operator tblRating.Id = dc.tblRatings.Any() ? dc.tblRatings.Max(dt => dt.Id) + 1 : 1; //Change the ID of the inserted Student rating.Id = tblRating.Id; dc.tblRatings.Add(tblRating); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Insert(out int id, string description) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating newrow = new tblRating(); newrow.Description = description; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblRatings.Any() ? dc.tblRatings.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; //add the row dc.tblRatings.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static Rating LoadById(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating row = (from dt in dc.tblRatings where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new Rating { Id = row.Id, Description = row.Description } } ; else { throw new Exception("Row was not found"); } } } catch (Exception ex) { throw ex; } }
public ActionResult DeleteConfirmed(int id) { tblRating tblRating = db.tblRatings.Find(id); db.tblRatings.Remove(tblRating); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { tblRating tblRating = db.tblRating.Find(id); db.Database.ExecuteSqlCommand("DELETE FROM tblRating WHERE idRating = @Rating)", new SqlParameter("idRating", tblRating.idRating) ); return(RedirectToAction("Index")); }
public void Delete() { using (DVDEntities dc = new DVDEntities()) { tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == -99); dc.tblRatings.Remove(rating); int rowsEffected = dc.SaveChanges(); Assert.IsTrue(rowsEffected == 1); } }
public ActionResult Delete(int?id) { tblRating rating = context.tblRatings.Find(id); if (rating != null) { context.tblRatings.Remove(rating); context.SaveChanges(); } return(RedirectToAction("ModIndex")); }
public ActionResult Edit([Bind(Include = "ID,ID_User,ID_Local,Rate")] tblRating tblRating) { if (ModelState.IsValid) { db.Entry(tblRating).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID_Local = new SelectList(db.tblLocals, "ID", "Name", tblRating.ID_Local); ViewBag.ID_User = new SelectList(db.tblUsers, "ID", "ID", tblRating.ID_User); return(View(tblRating)); }
public ActionResult Edit([Bind(Include = "idRating,Rating")] tblRating tblRating) { if (ModelState.IsValid) { db.Database.ExecuteSqlCommand("UPDATE tblRating SET Rating = @Rating)", new SqlParameter("Rating", tblRating.Rating) ); return(RedirectToAction("Index")); } return(View(tblRating)); }
public ActionResult Create([Bind(Include = "idRating,Rating")] tblRating tblRating) { if (ModelState.IsValid) { db.Database.ExecuteSqlCommand("INSERT into tblRating VALUES (@Rating)", new SqlParameter("Rating", tblRating.Rating) ); return(RedirectToAction("Index")); } return(View(tblRating)); }
public void Update() { using (DVDEntities dc = new DVDEntities()) { tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == -99); rating.Description = "Updt"; //Save changed property dc.SaveChanges(); tblRating updatedRating = dc.tblRatings.FirstOrDefault(r => r.Description == "Updt"); Assert.AreEqual(rating.Id, updatedRating.Id); } }
public IHttpActionResult PostDisplayRate(string id, string userID, [FromBody] int rate) { tblRating rating = new tblRating(); rating.RateId = Guid.NewGuid().ToString("N").Substring(0, 5).ToUpper(); rating.ProductId = id; rating.Rating = rate; rating.UserId = userID; db.tblRatings.Add(rating); db.SaveChanges(); return(Ok()); }
// GET: Ratings/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblRating tblRating = db.tblRatings.Find(id); if (tblRating == null) { return(HttpNotFound()); } return(View(tblRating)); }
public ActionResult AddRating(DetailsViewModel addratingvm) { if (ModelState.IsValid) { string username = User.Identity.Name; tblRating rating = new tblRating(addratingvm.Record.RecordID, addratingvm.Comment, addratingvm.Rating, username); context.tblRatings.Add(rating); context.SaveChanges(); return(RedirectToAction("Details", "Record", new { id = addratingvm.Record.RecordID })); } else { return(RedirectToAction("Details", "Record", new { id = addratingvm.Record.RecordID })); } }
public void InsertTest() { tblRating newrow = new tblRating(); // Set the column values newrow.Id = -99; newrow.Description = "Test"; // Insert of the row dc.tblRatings.Add(newrow); // Commit the changes (insert a row) and then return the rows affected. int rowsaffected = dc.SaveChanges(); Assert.AreNotEqual(0, rowsaffected); }
// GET: Ratings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblRating tblRating = db.tblRatings.Find(id); if (tblRating == null) { return(HttpNotFound()); } ViewBag.ID_Local = new SelectList(db.tblLocals, "ID", "Name", tblRating.ID_Local); ViewBag.ID_User = new SelectList(db.tblUsers, "ID", "ID", tblRating.ID_User); return(View(tblRating)); }
public void DeleteTest() { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating row = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); dc.tblRatings.Remove(row); int results = dc.SaveChanges(); Assert.AreNotEqual(0, results); } }
public void InsertTest() { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating newrow = new tblRating(); newrow.Id = -99; newrow.Description = "Z"; dc.tblRatings.Add(newrow); int results = dc.SaveChanges(); Assert.IsTrue(results == 1); } }
public static int Update(int id, string description) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating updaterow = (from dt in dc.tblRatings where dt.Id == id select dt).FirstOrDefault(); updaterow.Description = description; return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Delete(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating deleterow = (from dt in dc.tblRatings where dt.Id == id select dt).FirstOrDefault(); dc.tblRatings.Remove(deleterow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public void UpdateTest() { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating row = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); if (row != null) { row.Description = "V"; } int results = dc.SaveChanges(); Assert.AreNotEqual(0, results); } }
public void UpdateTest() { tblRating existingRating = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); if (existingRating != null) { // Update the description existingRating.Description = "Test"; dc.SaveChanges(); } tblRating updatedRating = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); Assert.AreEqual(existingRating, updatedRating); }
public void DeleteTest() { tblRating existingRating = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); if (existingRating != null) { // Delete the row dc.tblRatings.Remove(existingRating); dc.SaveChanges(); } tblRating deletedRating = (from dt in dc.tblRatings where dt.Id == -99 select dt).FirstOrDefault(); Assert.IsNull(deletedRating); }
public FCASystemViewModal(int id) { _locid = id; _tblBuildingSystem = new tblBuildingSystem(); _tblSystemElement = new tblSystemElement(); _tblRating = new tblRating(); _tblSystemType = new tblSystemType(); BuildingSystemList = _tblBuildingSystem.GetAll(); SystemElementList = new List <SystemElement>() { new SystemElement { SystemElementID = 0, SystemElementName = "Select System Element" } }; RatingList = _tblRating.GetAll(); SystemTypeList = _tblSystemType.GetAll(); //isRepairList = new IList<string> { "Yes", "No"}; }