public virtual void Delete(Expression <Func <T, bool> > where) { foreach (var t in _dbSet.Where(where).AsEnumerable()) { _dataContext.Entry(t).State = EntityState.Deleted; _dbSet.Remove(t); } }
public TEntity Update(TEntity obj) { var entry = _context.Entry(obj); DbSet.Attach(obj); entry.State = EntityState.Modified; _context.SaveChanges(); return(obj); }
/// <summary> /// Deletes preset entity /// </summary> /// <param name="entityToDelete">Entity to delete</param> /// <exception cref="ArgumentNullException"> /// Throws when passed <paramref name="entityToDelete"/> is null /// </exception> public void Delete(object entityToDelete) { if (entityToDelete == null) { throw new ArgumentNullException(nameof(entityToDelete)); } if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public ActionResult Edit(Transaction transaction) { if (ModelState.IsValid) { db.Entry(transaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Transactions")); } ViewBag.PersonGuid = new SelectList(db.Persons, "PersonGuid", "LoginId", transaction.PersonGuid); ViewBag.TransactionFor = new SelectList(db.TransactionFor.Where(x => x.TransactionType == (int)transaction.TranscationType), "TranscationForGuid", "TranscationFor"); return(View(transaction)); }
public ActionResult Edit(Withdrawal withdraw) { if (ModelState.IsValid) { Transaction transaction = db.Transactions.FirstOrDefault(x => x.TranscationGuid == withdraw.TranscationGuid); if (transaction == null) { return(HttpNotFound()); } log.Info(withdraw.TranscationGuid); log.Info(transaction.TranscationGuid); transaction.TranscationForGuid = withdraw.TranscationForGuid; transaction.PersonGuid = withdraw.PersonGuid; transaction.Amount = withdraw.Amount; transaction.Interest = withdraw.Interest; transaction.TransactionDate = withdraw.TransactionDate; db.Entry(transaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Transactions")); } ViewBag.TransactionFor = new SelectList(db.TransactionFor.Where(x => x.TransactionType == 2), "TranscationForGuid", "TranscationFor"); ViewBag.PersonGuid = new SelectList(db.Persons, "PersonGuid", "LoginId", withdraw.PersonGuid); return(View(withdraw)); }
internal void UpdateBalance(BalanceModel updateBalance) { using (Context.AppContext dbContext = new Context.AppContext()) { BalanceModel currentBalance = dbContext.Balance.FirstOrDefault(b => b.Id == updateBalance.Id); dbContext.Entry(currentBalance).CurrentValues.SetValues(updateBalance); dbContext.SaveChanges(); } }
internal void UpdateCategory(CategoryModel updateCategory) { using (Context.AppContext dbContext = new Context.AppContext()) { CategoryModel currentCategory = dbContext.Categories.FirstOrDefault(c => c.Id == updateCategory.Id); dbContext.Entry(currentCategory).CurrentValues.SetValues(updateCategory); dbContext.SaveChanges(); } }
internal void UpdateCost(CostModel updateCost) { using (Context.AppContext dbContext = new Context.AppContext()) { CostModel currentCost = dbContext.Costs.FirstOrDefault(c => c.Id == updateCost.Id); dbContext.Entry(currentCost).CurrentValues.SetValues(updateCost); dbContext.SaveChanges(); } }
public ActionResult Put(int id, [FromBody] Contacto contacto) { if (contacto.idContacto == id) { context.Entry(contacto).State = EntityState.Modified; context.SaveChanges(); return(Ok()); } else { return(BadRequest()); } }
public ActionResult Edit(Investment investment) { if (ModelState.IsValid) { db.Entry(investment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } var category = ConfigurationManager.AppSettings["InvestmentCategory"]; var list = category.Split(',').Select(x => new { item = x, value = x }); ViewBag.InvestmentTypes = new SelectList(list, "value", "item"); ViewBag.TransactionType = new SelectList(new List <object>() { new { item = "Credit", value = 1 }, new { item = "Debit", value = 2 } }, "value", "item", investment.InvestmentType); return(View(investment)); }
public ActionResult Edit([Bind(Exclude = "TechnologyContents")] Technology technology) { try { if (ModelState.IsValid) { db.Entry(technology).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(technology)); } catch (Exception ex) { log.Error("TechnologyController Edit- Post Action : " + ex.Message); return(RedirectToAction("Index", "Error", new { exception = ex })); } }
public ActionResult Edit([Bind(Exclude = "Technology")] TechnologyContent technologyContent) { try { if (ModelState.IsValid) { db.Entry(technologyContent).State = EntityState.Modified; technologyContent.Description = HttpContext.Server.HtmlEncode(technologyContent.Description); technologyContent.Example = HttpContext.Server.HtmlEncode(technologyContent.Example); db.SaveChanges(); return(RedirectToAction("Details", "Technology", new { id = technologyContent.TechnologyContentGuid })); } ViewBag.TechnologyGuid = new SelectList(db.Technologies.AsNoTracking(), "TechnologyGuid", "TechnologyName", technologyContent.TechnologyGuid); return(View(technologyContent)); } catch (Exception ex) { log.Error("TechnologyContentController Edit- Post Action : " + ex.Message); return(RedirectToAction("Index", "Error", new { exception = ex })); } }
public ActionResult Edit(Voluntario model) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Voluntario")); }
public void Update(T entity) { _dbSet.Attach(entity); _dataContext.Entry(entity).State = EntityState.Modified; }
public ActionResult Edit(Professor model) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Professor")); }
public virtual void Edit(T entity) { _context.Entry(entity).State = EntityState.Modified; _context.SaveChanges(); }