Beispiel #1
0
        public int AddBook(Book book)
        {
            int result = 0;

            if (context != null)
            {
                context.Books.Add(book);
                result = context.SaveChanges();
            }
            return(result);
        }
Beispiel #2
0
        public IActionResult Create(EmployeeModel employeeModel)
        {
            if (ModelState.IsValid)
            {
                _databaseDbContext.employee.Add(employeeModel);
                _databaseDbContext.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(employeeModel));
        }
Beispiel #3
0
        public bool Add(Student student)
        {
            int isExecuted = 0;

            db.Students.Add(student);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #4
0
 public static void CleanDatabase(TestContext context)
 {
     using (var db = new DatabaseDbContext())
     {
         //db.students.RemoveRange(db.students);
         //db.parents.RemoveRange(db.parents);
         //db.tutors.RemoveRange(db.tutors);
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public string InsertDoctors(DoctorRequest request)
 {
     _context.Doctors.Add(new Doctor
     {
         Id        = request.IdDoctor,
         FirstName = request.FirstName,
         LastName  = request.LastName,
         Email     = request.Email
     });
     try
     {
         _context.SaveChanges();
     }
     catch (Exception)
     {
         return(null);
     }
     return("A doctor has been successfully added");
 }
        public bool Save(IConfiguration configToSave)
        {
            Console.WriteLine(" ---- > Enter to Save method");
            _context.Set <T>();
            Console.WriteLine(" ---- > Set entity....");

            _context.Add(configToSave);
            Console.WriteLine(" ---- > Add to context");

            _context.SaveChanges();

            Console.WriteLine("Save to Database....");
            return(true);
        }
 public virtual void Update(TEntity entity)
 {
     entity.Date = DateTime.UtcNow;
     DbContext.Entry(entity).State = EntityState.Modified;
     DbContext.SaveChanges();
 }