public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Age,Gender")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("Id,DepartmentName")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("id,first_name,last_name")] Students students)
        {
            if (ModelState.IsValid)
            {
                _context.Add(students);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,NormalizedName,ConcurrencyStamp")] AspNetRole aspNetRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aspNetRole);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aspNetRole));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Id,Nume,Prenume,An,Facultate,Camera,Etaj,Sex,TaxaAchitata")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] AspNetUser aspNetUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aspNetUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aspNetUser));
        }
        public IActionResult PostStudents(string name, int id)
        {
            var Students = new Students()
            {
                Student_Name = name,
                Group_Id     = id
            };

            _context.Add(Students);
            _context.SaveChanges();
            return(Ok("Created"));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,StuID,DepartmentId")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", student.DepartmentId);
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("UserId,RoleId")] AspNetUserRole aspNetUserRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aspNetUserRole);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.AspNetRoles, "Id", "Id", aspNetUserRole.RoleId);
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUserRole.UserId);
            return(View(aspNetUserRole));
        }
Example #10
0
        public static void AddDepartments()
        {
            Department department = new Department {
                Name = "Katedrav za SI"
            };
            StudentsContext context = new StudentsContext();

            //context.Add(new Department { Name = "Katedra za IT" });
            //context.Add(new Department { Name = "Katedra za IS" });
            //context.Add(new Department { Name = "Katedra za OI" });
            //context.Add(new Department { Name = "Katedra za M" });
            context.Add(department);
            context.SaveChanges();
            context.Dispose();
        }
Example #11
0
        public static void AddSubject()
        {
            int        id         = 1;
            Department department = context.Departments.Single(d => d.DepartmentId == id);
            Subject    s          = new Subject
            {
                Name         = "Napredne .NET tehnologije",
                ESPB         = 6,
                DepartmentId = 2
            };

            context.Add(s);
            context.SaveChanges();
        }
        public async Task <IActionResult> Create(int?id, Student studentmodel)
        {
            if (ModelState.IsValid)
            {
                Student student = new Student();
                student.StudentName    = studentmodel.StudentName;
                student.StudentSurname = studentmodel.StudentSurname;
                student.StudentNo      = studentmodel.StudentNo;
                student.StudentTelNo   = studentmodel.StudentTelNo;
                student.StudentEmail   = studentmodel.StudentEmail;
                student.DepartmentId   = studentmodel.DepartmentId;
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(studentmodel));
        }
Example #13
0
        static void Main(string[] args)
        {
            //instantiate an instance of the context
            StudentsContext context = new StudentsContext();

            //make sure that the table exists, and create it if it does not already exist.
            context.Database.EnsureCreated();

            //ask the user for a student to add
            Console.WriteLine("Enter Student full name");
            string fullName = Console.ReadLine();

            //split the input into parts, and make sure we have 2 parts only
            string[] parts = fullName.Split();
            if (parts.Length == 2)
            {
                //create a new student object, notice that we do not select an id, we let the framework handle that
                Student newStudent = new Student(parts[0], parts[1]);

                //add the newly created student instance to the context.
                //notice how similar this is to adding an item to a list.
                context.Add(newStudent);

                //ask the context to save any changes to the database
                context.SaveChanges();
                Console.WriteLine("Added the student.");
            }
            else
            {
                Console.WriteLine("Invalid full name, did not add student.");
            }

            Console.WriteLine("The Current List of students is: ");
            //use a foreach loop to loop through the students in the context
            //notice how similar this is to looping through a list
            foreach (Student s in context.students)
            {
                Console.WriteLine("{0} - {1} {2}", s.ID, s.FirstName, s.LastName);
            }
        }
Example #14
0
 public void Add(Student s)
 {
     context.Add(s);
 }