Ejemplo n.º 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);
     }
 }
        public TEntity Update(TEntity obj)
        {
            var entry = _context.Entry(obj);

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


            return(obj);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
        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));
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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());
     }
 }
        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));
        }
Ejemplo n.º 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 }));
     }
 }
Ejemplo n.º 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 }));
     }
 }
 public ActionResult Edit(Voluntario model)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index", "Voluntario"));
 }
Ejemplo n.º 14
0
        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"));
 }
Ejemplo n.º 16
0
 public virtual void Edit(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }