コード例 #1
0
 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);
     }
 }
コード例 #2
0
        public TEntity Update(TEntity obj)
        {
            var entry = _context.Entry(obj);

            DbSet.Attach(obj);
            entry.State = EntityState.Modified;
            _context.SaveChanges();


            return(obj);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
 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();
     }
 }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
 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());
     }
 }
コード例 #10
0
        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));
        }
コード例 #11
0
 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 }));
     }
 }
コード例 #12
0
 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 }));
     }
 }
コード例 #13
0
 public ActionResult Edit(Voluntario model)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index", "Voluntario"));
 }
コード例 #14
0
        public void Update(T entity)
        {
            _dbSet.Attach(entity);

            _dataContext.Entry(entity).State = EntityState.Modified;
        }
コード例 #15
0
 public ActionResult Edit(Professor model)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index", "Professor"));
 }
コード例 #16
0
ファイル: GenericRepository.cs プロジェクト: Svaly/CRC
 public virtual void Edit(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }