public ActionResult Create([Bind(Include = "ID,Name,Age,Role,BirthDate")] Developers developers) { if (ModelState.IsValid) { db.Developers.Add(developers); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(developers)); }
private void Update(int id, string name, int age, DateTime birthdate, Role role, List <int> skills) { using (DevContext context = new DevContext()) { var updateDeveloper = db.Developers.Where(x => x.ID == id).First(); updateDeveloper.Name = name; updateDeveloper.Age = age; updateDeveloper.BirthDate = birthdate; updateDeveloper.Role = role; updateDeveloper = UpdateSkill(skills, updateDeveloper, context); db.Entry(updateDeveloper).State = EntityState.Modified; db.SaveChanges(); } }
public void Insert(T entity) { try { if (entity == null) { throw new ArgumentNullException("entity"); } Entities.Add(entity); _context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { errorMessage += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine; } } Log.Error(errorMessage, dbEx); } }
public static void Add(string name, int age, DateTime birthdate, Role role, List <int> skills) { using (DevContext ctx = new DevContext()) { var developer = new Developers() { Name = name, Age = age, BirthDate = birthdate, Role = role }; foreach (var skillid in skills) { var skill = ctx.SkillLists.Find(skillid); developer.Skills.Add(skill); } ctx.Developers.Add(developer); ctx.SaveChanges(); } }
public void Commit() { _context.SaveChanges(); }
public void Save() { context.SaveChanges(); }
public void Save() { ctx.SaveChanges(); }