public IActionResult Add(ToDoViewModel model) { if (ModelState.IsValid) { _context.tbl_ToDos.Add(model.CurrentTask); _context.SaveChanges(); return(RedirectToAction("Index", "Todo")); } else { model.Categories = _context.tbl_Categories.ToList(); model.Statuses = _context.tbl_Statuses.ToList(); return(View(model)); } }
public static void UpdateSpecificProperties <TEntity> (TEntity entity, List <string> props) where TEntity : class { var ctx = new AppDbContext2(); var entityType = ctx.Model.GetEntityTypes() .FirstOrDefault(w => w.ClrType.Name == entity.GetType().Name); if (entityType == null) { throw new Exception($"There isn't any matched entity in {ctx.GetType().Name}"); } var properties = entityType.GetProperties().Select(s => s.Name).ToList(); foreach (var prop in props) { if (properties.Contains(prop)) { ctx.Entry(entity).Property(prop).IsModified = true; } } ctx.SaveChanges(); }
public m_cls_Company_D Add(m_cls_Company_D company) { _db.tbl_Company_D.Add(company); _db.SaveChanges(); return(company); }