Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
 public void Commit()
 {
     _context.SaveChanges();
 }
Exemplo n.º 6
0
 public void Save()
 {
     context.SaveChanges();
 }
Exemplo n.º 7
0
 public void Save()
 {
     ctx.SaveChanges();
 }