示例#1
0
        public void TestMethod1()
        {
            bool access = true;

            try
            {
                StudentDb   stu     = new StudentDb();
                StudentData studata = new StudentData
                {
                    IdCard            = "342626200001180191",
                    Address           = "安徽马鞍山",
                    Telephone         = "17855527769",
                    PareventTelephone = "18855579263"
                };
                StudentDetialData stuDetial = new StudentDetialData
                {
                    Name         = "李俊",
                    Department   = "计算机系",
                    Class        = "18网络2班",
                    StudentDatas = studata
                };
                studata.StudentDetialDatas = stuDetial;
                stu.studentDetialDatas.Remove(stuDetial);
                stu.SaveChanges();
            }
            catch
            {
                access = false;
                Console.WriteLine("出现错误");
            }
            Assert.AreEqual(access, true);
        }
示例#2
0
        private StudentDetail ConvertToStudentDetail(StudentDb studentDb)
        {
            DateTime?lastSignIn = null;

            if (studentDb.User.SignIns != null && studentDb.User.SignIns.Any())
            {
                lastSignIn = studentDb.User.SignIns.Max(t => t.SigninTime);
            }

            var sortedSigninHistory = studentDb.User.SignIns.OrderBy(s => s.Id);


            StudentDetail student = new StudentDetail()
            {
                StudentId       = studentDb.StudentId,
                SignUpSource    = studentDb.SignUpSource,
                Notes           = studentDb.Notes,
                Avatar          = studentDb.Avatar,
                School          = studentDb.School,
                Mobile          = studentDb.Mobile,
                City            = studentDb.City,
                Address         = studentDb.Address,
                Title           = studentDb.Title,
                CurrentSigninIp = sortedSigninHistory.Count() > 0 ? sortedSigninHistory.TakeLast(1).FirstOrDefault().SigninIp : string.Empty,
                LastSigninIp    = sortedSigninHistory.Count() > 1 ? sortedSigninHistory.TakeLast(2).FirstOrDefault().SigninIp : string.Empty,
                NumberOfLogins  = studentDb.User.SignIns.Count,
            };

            return(student);
        }
        public static void AddStudent()
        {
            Console.Clear();
            Console.Write("First name: ");
            string firstName = Console.ReadLine();

            Console.Write("Last name: ");
            string lastName = Console.ReadLine();

            Console.Write("Date of birth: ");
            bool result = DateTime.TryParse(Console.ReadLine(), out DateTime dateOfBirth);

            while (!result || dateOfBirth > DateTime.Now)
            {
                Console.Write("Wrong input!\nDate of birth has to be set as YYYY/MM/DD and can't be a future date \nDate of Birth: ");
                result = DateTime.TryParse(Console.ReadLine(), out dateOfBirth);
            }
            Console.Write("Tuition Fees: ");
            result = decimal.TryParse(Console.ReadLine(), out decimal tuitionFees);
            while (!result || tuitionFees < 0)
            {
                Console.Write("Wrong input!\n Tuition fees can't be a negative number \nTuition Fees: ");
                result = decimal.TryParse(Console.ReadLine(), out tuitionFees);
            }
            StudentDb.AddStudent(firstName, lastName, dateOfBirth, tuitionFees);
            Console.Clear();

            Console.WriteLine("Student added successfully!\n");
        }
示例#4
0
 public IEnumerable <Student> Get()
 {
     using (StudentDb db = new StudentDb())
     {
         return(db.Students.ToList());
     }
 }
示例#5
0
 public Student Get(int id)
 {
     using (StudentDb db = new StudentDb())
     {
         return(db.Students.First(t => t.Id == id));
     }
 }
示例#6
0
        public void EfUpdate()
        {
            ISchoolAdministratorDal dal = new SchoolAdministratorDal("EFDAL");
            StudentDb stu    = new StudentDb();
            var       entity = stu.SchoolAdministrators.FirstOrDefault(x => x.AdministratorAccount == "1316279031");
            //entity.AdministratorPassword = "******";
            //entity.CreateAdminitratorDetialDatas.CreatedTime = DateTime.Now.AddDays(5);
            //entity.CreateAdminitratorDetialDatas.Email = "*****@*****.**";
            //entity.CreateAdminitratorDetialDatas.IsFreeze = true;
            bool isbool            = false;
            SchoolAdministrator sc = new SchoolAdministrator()
            {
                AdministratorAccount          = "1316279031",
                AdministratorPassword         = "******",
                CreateAdminitratorDetialDatas = new CreateAdminitratorDetialData()
                {
                    AdministratorAuthority = "校长",
                    CreatedTime            = DateTime.Now.Date,
                    Email    = "*****@*****.**",
                    IsFreeze = false,
                    Message  = "Heelo"
                }
            };

            Console.WriteLine(entity.AdministratorAccount);
            //isbool=dal.Update(entity);
            stu.Entry(entity).CurrentValues.SetValues(sc);
            isbool = stu.SaveChanges() > 0;
            Assert.AreEqual(isbool, true);
        }
示例#7
0
        public IActionResult Edit(int id)
        {
            //get the student by id
            Student s = StudentDb.GetStudent(context, id);

            //show the student on the web page
            return(View(s));
        }
        public IActionResult DeleteConfirm(Student p)
        {
            StudentDb.Delete(context, p);
            TempData["Message"] = "Student successfully deleted.";


            return(RedirectToAction("Index"));
        }
示例#9
0
        public IActionResult Edit(int id)
        {
            //get the product by id
            Student p = StudentDb.GetStudent(context, id);

            //show it on web page
            return(View(p));
        }
示例#10
0
        public async Task <IActionResult> Update(int id)
        {
            //get the product by id
            Student p = await StudentDb.GetStudent(context, id);

            //show it on web page
            return(View(p));
        }
示例#11
0
        //The details IActionResult was missing from the original project.
        public IActionResult Details(int id)
        {
            //This view is readonly.
            //Get the student to be displayed on the page
            Student s = StudentDb.GetStudent(context, id);

            return(View(s));
        }
示例#12
0
        public IActionResult Delete(int id)
        {
            //Get Product from database
            Student p = StudentDb.GetStudent(context, id);

            StudentDb.Delete(context, p);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> DeleteConfirm(int id)
        {
            //Get Product from database
            Student p = await StudentDb.GetStudent(context, id);

            await StudentDb.Delete(context, p);

            return(RedirectToAction("Index"));
        }
示例#14
0
        public void Post([FromBody] JObject value)
        {
            Student posted = value.ToObject <Student>();

            using (StudentDb db = new StudentDb())
            {
                db.Students.Add(posted);
                db.SaveChanges();
            }
        }
示例#15
0
        public IActionResult DeleteConfirm(int id)
        {
            //Get the student to be deleted from the database.
            Student s = StudentDb.GetStudent(context, id);

            //Delete the student from the Database.
            StudentDb.Delete(context, s);

            return(RedirectToAction("Students"));
        }
示例#16
0
        public void Put(int id, [FromBody] JObject value)
        {
            Student posted = value.ToObject <Student>();

            posted.Id = id;
            using (StudentDb db = new StudentDb())
            {
                db.Students.Update(posted);
                db.SaveChanges();
            }
        }
示例#17
0
 public void Delete(int id)
 {
     using (StudentDb db = new StudentDb())
     {
         if (db.Students.Where(t => t.Id == id).Count() > 0)
         {
             db.Students.Remove(db.Students.First(t => t.Id == id));
             db.SaveChanges();
         }
     }
 }
示例#18
0
        public async Task <IActionResult> Update(Student p)
        {
            if (ModelState.IsValid)
            {
                await StudentDb.UpdateStudent(p, context);

                return(RedirectToAction("Index"));
            }
            //return view with errors
            return(View(p));
        }
示例#19
0
 public IActionResult Edit(Student p)
 {
     if (ModelState.IsValid)
     {
         StudentDb.Update(context, p);
         ViewData["Message"] = "Product Updated!";
         return(View(p));
     }
     //return view with errors
     return(RedirectToAction("Index"));
 }
示例#20
0
        public async Task <IActionResult> Create(Student p)
        {
            if (ModelState.IsValid)
            {
                await StudentDb.Add(p, context);

                return(RedirectToAction("Index"));
            }

            //Show web page with errors
            return(View(p));
        }
        public IActionResult Create(Student stu)
        {
            if (ModelState.IsValid)
            {
                StudentDb.Add(stu, context);
                ViewData["Message"] = $"{stu.Name} was added!";
                return(RedirectToAction(nameof(Index)));
            }

            //Show web page with errors
            return(View(stu));
        }
示例#22
0
        public IActionResult Create(Student p)
        {
            if (ModelState.IsValid)
            {
                StudentDb.Add(p, context);
                ViewData["Message"] = $"{p.Name} was added!";
                return(View());
            }

            //Show web page with errors
            return(View(p));
        }
示例#23
0
        public async Task <IActionResult> Create(Student p)
        {
            if (ModelState.IsValid)
            {
                await StudentDb.AddAsync(p, context);

                ViewData["Message"] = $"{p.Name} was added!";
                return(RedirectToAction("Index"));
            }

            //Show web page with errors
            return(View(p));
        }
示例#24
0
        public IActionResult DeleteConfirm(int id)
        {
            //Get Product from database
            Student p = StudentDb.GetStudent(context, id);

            StudentDb.Delete(context, p);

            context.Students.Remove(p);

            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#25
0
 public IActionResult Edit(Student p)
 {
     if (ModelState.IsValid)
     {
         StudentDb.Update(context, p);
         context.Update(p);
         context.SaveChanges();
         ViewData["Message"] = "Product Updated!";
         return(View(p));
     }
     //return view with errors
     return(View(p));
 }
        public async Task <IActionResult> DeleteConfirm(int id)
        {
            //Get Product from database
            Student p = await StudentDb.GetStudent(context, id);

            context.Entry(p).State = EntityState.Deleted;

            await context.SaveChangesAsync();

            TempData["Message"] = $"{p.Name} was deleted";

            return(RedirectToAction("Index"));
        }
示例#27
0
 public IActionResult Edit(Student s)
 {
     if (ModelState.IsValid)
     {
         //updates a student in the database.
         StudentDb.Update(context, s);
         //use TempData instead of ViewData here,
         //because the message will not display, otherwise
         TempData["Message"] = "The Student was updated successfully!";
         return(RedirectToAction("Students"));
     }
     //return view with errors
     return(View(s));
 }
        public IActionResult RegisterMB(Student s)
        {
            // This verifies all data annotations in the class are valid
            if (ModelState.IsValid)
            {
                // Add to database
                StudentDb.Register(s);

                // Display success message
                ViewData["Success"] = "Student was succesfully registered!";
                return(View());
            }
            return(View());
        }
示例#29
0
        public IActionResult Create(Student s)
        {
            if (ModelState.IsValid)
            {
                //Add the student to the DB
                StudentDb.Add(s, context);
                TempData["Message"] = $"{s.Name} was added!";
                //Redirects the user to the students page
                //after a student is added
                return(RedirectToAction("Students"));
            }

            //Show web page with errors
            return(View(s));
        }
示例#30
0
        public static Student ToStudent(StudentDb studentDb)
        {
            if (studentDb == null)
            {
                return(null);
            }

            return(new Student
            {
                Id = studentDb.id,
                Surname = studentDb.surname,
                Name = studentDb.name,
                Patronymic = studentDb.patronymic,
                UniqCode = studentDb.uniq_code,
                Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), studentDb.gender)
            });
        }