コード例 #1
0
ファイル: Program.cs プロジェクト: wetall24/wetall
        static void Main(string[] args)
        {
            StudentService service = new StudentService();

            service.Add(new Student
            {
                Name     = "Ivan",
                Age      = 20,
                Lastname = "Ivanov",
            });
            service.Add(new Student
            {
                Name     = "Petro",
                Age      = 22,
                Lastname = "Petrenko",
            });
            Random rand = new Random();

            foreach (Student item in service.Students)
            {
                item.AddMark("C++", rand.Next(1, 12));
                item.AddMark("C#", rand.Next(1, 12));
            }
            foreach (var item in service.Students)
            {
                Console.WriteLine(item);
            }
            service.Save();
        }
コード例 #2
0
ファイル: StudentTests.cs プロジェクト: codehaks/MySchool
        public async Task New_Student_Can_Be_Added_To_Class()
        {
            var options = new DbContextOptionsBuilder <PortalDbContext>()
                          .UseInMemoryDatabase(databaseName: "Not_Same_Student_Db")
                          .Options;

            using (var context = new PortalDbContext(options))
            {
                var service = new StudentService(context);
                var count   = (await service.GetAll()).Count();
                await service.Add(new Domain.Entities.Student()
                {
                    ClassId = 1, Age = 19, GPA = 3.2f, Name = "Jones"
                });

                await service.Add(new Domain.Entities.Student()
                {
                    ClassId = 1, Age = 18, GPA = 3.0f, Name = "David"
                });

                var countAfter = (await service.GetAll()).Count();

                Assert.Equal(countAfter, count + 2);
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            StudentService StudentService = new StudentService();

            StudentService.Add(new Student
            {
                Name     = "Ivan",
                LastName = "Ivanov",
                Age      = 20
            }
                               );

            StudentService.Add(new Student
            {
                Name     = "Petro",
                LastName = "Ivanov",
                Age      = 20
            }
                               );

            Random rnd = new Random();

            foreach (Student item in StudentService.Students)
            {
                item.AddMark("C++", rnd.Next(1, 12));
                item.AddMark("C#", rnd.Next(1, 12));
            }
            foreach (Student item in StudentService.Students)
            {
                Console.WriteLine(item);
            }
            StudentService.Save();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            StudentService service = new StudentService();

            service.Add(new Student
            {
                Name     = "Andrii",
                Age      = 16,
                LastName = "Pashko",
            });
            service.Add(new Student
            {
                Name     = "Petro",
                Age      = 23,
                LastName = "Pavlov",
            });
            Random rnd = new Random();

            foreach (Student item in service.Students)
            {
                item.AddMark("C++", rnd.Next(1, 12));
                item.AddMark("C#", rnd.Next(1, 12));
            }
            foreach (var item in service.Students)
            {
                Console.WriteLine(item);
            }
            service.Save();
            service.Best();
        }
コード例 #5
0
        public void Add_StudentNull_NullArgumentException()
        {
            StudentDto student = null;


            Assert.Throws <ArgumentNullException>(() => { studentService.Add(student); });
        }
コード例 #6
0
        public ActionResult Edit(Student std)
        {
            Student student;

            if (ModelState.IsValid)
            {
                var  students          = StudentSVC.GetAll();
                bool nameAlreadyExists = StudentSVC.NameAlreadyExist(std);
                if (nameAlreadyExists)
                {
                    ModelState.AddModelError(String.Empty, "Student Name already exist");
                }
                if (std.StudentId == 0)
                {
                    //generate Id
                    StudentSVC.Add(std);
                }
                else
                {
                    StudentSVC.Edit(std);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(std));
            }
        }
コード例 #7
0
 public ActionResult Create(StudentAccount model)
 {
     model.ID = Guid.NewGuid();
     students.Add(model);
     students.Save();
     return(RedirectToAction("Index"));
 }
コード例 #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (StudentService studentService = new StudentService())
            {
                DialogResult dr = MessageBox.Show("Kaydetmek istediğinize emin misiniz?", "Onay", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dr == DialogResult.Yes)
                {
                    StudentDTO student = new StudentDTO
                    {
                        FirstName    = txtFirstName.Text,
                        LastName     = txtLastName.Text,
                        TcNumber     = txtTCNumber.Text,
                        MobilePhone  = txtMobilePhone.Text,
                        EmailAddress = txtEmailAdress.Text,
                        CreatedBy    = 1
                    };

                    var result = studentService.Add(student);

                    student.StudentCoursList = studentcourses;

                    if (result != null)
                    {
                        MessageBox.Show("Kayıt başarılı", "Durum", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Kayıt sırasında bir hata oluştu", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
コード例 #9
0
        private string AddStudent()
        {
            student Student = (student)ObjectUtil.FillObjectWithMap(new student(), BaseService.ReqToDict(Request));

            if (Student != null)
            {
                studentService = new StudentService();
                student Std = null;
                if (StringUtil.NotNullAndNotBlank(Student.id))
                {
                    Std = (student)studentService.Update(Student);
                }
                else
                {
                    Std = (student)studentService.Add(Student);
                }
                if (Std == null)
                {
                    return("0");
                }
                student toSend = (student)ObjectUtil.GetObjectValues(new string[] {
                    "id", "name", "bod", "class_id", "address", "email"
                }, Std);
                return(JsonConvert.SerializeObject(toSend));
            }
            return("0");
        }
コード例 #10
0
        public IHttpActionResult Post(Student student)
        {
            StudentService service = new StudentService();
            var            add     = service.Add(student);

            return(this.Ok(add));
        }
コード例 #11
0
 public ActionResult Create(Student student)
 {
     studentService.Add(student);
     student.StudentNumber = studentService.GetStudentNumber(student.ID);
     studentService.Update(student);
     return(RedirectToAction("Index"));
 }
コード例 #12
0
ファイル: StudentUT.cs プロジェクト: seydakurtdere/University
        public void Add()
        {
            StudentDTO student = new StudentDTO
            {
                FirstName      = "Seyda",
                LastName       = "Kurtdere",
                TcNumber       = "11111111111",
                MobilePhone    = "05348754962",
                EmailAddress   = "*****@*****.**",
                BranchId       = 1,
                RecordStatusId = 1,
                CreatedDate    = DateTime.Now,
                CreatedBy      = 1,
                BranchName     = "aaaa"
            };

            student.StudentCoursList = new System.Collections.Generic.List <StudentCoursDTO>();
            StudentCoursDTO studentCours1 = new StudentCoursDTO {
                CourseId = 1
            };
            StudentCoursDTO studentCours2 = new StudentCoursDTO {
                CourseId = 2
            };

            student.StudentCoursList.Add(studentCours1);
            student.StudentCoursList.Add(studentCours2);

            var result = studentService.Add(student);

            Assert.IsNotNull(result);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: grgec94/Project2
        static void Main(string[] args)
        {
            var service = new StudentService();

            HandleHelp();

            var    valid = false;
            string command;

            do
            {
                Console.Write("Command: ");
                command = Console.ReadLine();
                valid   = CommandValidator.IsValidCommand(command);
                command = command.ToUpper();
                switch (command)
                {
                case Operations.Enlist:
                    service.Add();
                    break;

                case Operations.Display:
                    service.HandleDisplay();
                    break;

                default:
                    Console.WriteLine("Invalid command!");
                    HandleHelp();
                    break;
                }
            } while (command != Operations.Exit);
        }
コード例 #14
0
        private static void Main()
        {
            AutoMapperConfig.Initialize();
            var studentService = new StudentService();

            var allStudents = studentService.GetAllAsync().Result;

            foreach (var student in allStudents)
            {
                Console.WriteLine(student.Name);
            }

            var student1 = studentService.GetAsync(1).Result;

            Console.WriteLine(student1.Name);

            var student2 = new StudentDto
            {
                Name     = "Petr",
                LastName = "Petrov",
                City     = "Konotop",
                Phone    = "+380000322"
            };

            studentService.Add(student2);

            var student3 = new StudentDto {
                Id = 1, Name = "Sergey", City = "Kyiv"
            };

            studentService.Update(student3);

            studentService.Remove(1);
        }
コード例 #15
0
 public void SaveButton()
 {
     if (SelectedStudent == null) //save button will add student to studentlist
     {
         StudentService.Add(new StudentModel
         {
             StudentId = StudentId,
             FirstName = FirstName,
             LastName  = LastName,
             Birthdate = BirthDate,
             Gender    = GetGender(BoolGender),
             City      = City,
             Email     = Email,
             Class     = Class
         }
                            );
     }
     else //save button will change data with selected student in mainviewmodel
     {
         SelectedStudent.StudentId = StudentId;
         SelectedStudent.FirstName = FirstName;
         SelectedStudent.LastName  = LastName;
         SelectedStudent.Birthdate = BirthDate;
         SelectedStudent.Gender    = GetGender(BoolGender);
         SelectedStudent.City      = City;
         SelectedStudent.Email     = Email;
         SelectedStudent.Class     = Class;
     }
     MessageBox.Show("Student has been successfully saved!");
     TryClose();
 }
コード例 #16
0
        public ActionResult Create(CreateStudentViewModel student)
        {
            if (ModelState.IsValid)
            {
                Lecture thisLecture = _lectureService.GetLecture(student.Lecture_Key);
                if (thisLecture != null)
                {
                    Student s = new Student
                    {
                        Lecture_ID   = thisLecture.ID,
                        Compeny      = student.Compeny,
                        Employee_ID  = student.Employee_ID,
                        Birthday     = student.Birthday,
                        Email        = student.Email,
                        Gender       = (int)student.Gender,
                        Name         = student.Name,
                        Phone_Number = student.Phone_Number,
                        CreateDate   = DateTime.Now,
                        Key          = Guid.NewGuid()
                    };
                    _studentService.Add(s);
                    _unitOfWork.Commit();

                    return(RedirectToAction("Index1", "Question", new { ID = 1, key = s.Key }));
                }
            }
            ViewBag.Lecture_Key = student.Lecture_Key;
            return(View(student));
        }
コード例 #17
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        // POST: api/Student
        public async Task <IHttpActionResult> Post([FromBody] Student value)
        {
            try
            {
                Student model = await bll.Add(value);

                if (model.Id > 0)
                {
                    return(this.JsonMy(new AjaxResult <Student> {
                        Code = 1, Msg = "添加成功"
                    }));
                }
                else
                {
                    return(this.JsonMy(new AjaxResult <Student> {
                        Code = 0, Msg = "请求失败"
                    }));
                }
            }
            catch (Exception e)
            {
                var msg = "请求失败";
#if DEBUG
                msg = e.Message;
#endif
                return(this.JsonMy(new AjaxResult <Student> {
                    Code = 0, Msg = msg
                }));
            }
        }
コード例 #18
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Student temp = stud.GetAllStudents[ComboStudName.SelectedIndex];

            stud.GetAllStudents.Remove(stud.GetAllStudents[ComboStudName.SelectedIndex]);
            stud.Add(temp);
            stud.SaveStud();
        }
コード例 #19
0
        private void btnsave_Click(object sender, System.EventArgs e)
        {
            student            = new Student();
            student.Name       = Convert.ToString(txtName.Text);
            student.BirthDate  = Convert.ToDateTime(dateBirth);
            student.Teacher.Id = Convert.ToInt32(cbxTeacher.SelectedItem);

            service.Add(student);
        }
コード例 #20
0
 public ActionResult Post(StudentEditViewModel editModel)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     studentService.Add(editModel);
     return(RedirectToAction("Get"));
 }
コード例 #21
0
 public ActionResult Student(StudentAccount account)
 {
     if (ModelState.IsValid)
     {
         db.Add(account);
         db.Save();
         return(RedirectToAction("Index", "MudurStudent", new { Areas = "Mudur" }));
     }
     return(View());
 }
コード例 #22
0
        public ActionResult Add(StudentEditViewModel Student)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            StudentService.Add(Student);
            return(RedirectToAction("Student"));
        }
コード例 #23
0
ファイル: StudentController.cs プロジェクト: z808089/EFDemo
        public ActionResult AddNew(string name, int age, long nationId)
        {
            StudentService stuService = new StudentService();

            stuService.Add(name, age, nationId, 1);
            // 重定向
            // return RedirectToAction("Index");使用下面的nameof(),减少自己编码中出现字符串作为参数,可避免不必要的错误
            //也可这么写:return Redirect("/Student/Index");
            return(RedirectToAction(nameof(StudentController.Index)));
        }
コード例 #24
0
 public ActionResult AddStudent()
 {
     Student s = new Student();
     s.Name = "111";
     s.Age = 12;
     s.Score = 100;
     StudentService ss = new StudentService();
     ss.Add(s);
     var list = ss.GetStudent();
     return Content("");
 }
コード例 #25
0
        public ActionResult Create([Bind(Include = "Id,Firstname")] Student student)
        {
            if (ModelState.IsValid)
            {
                Service.Add(student);

                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
コード例 #26
0
        static void Main(string[] args)
        {
            IStudentRepository repository = new StudentRepository();
            IStudentService    student    = new StudentService(repository);

            student.Add(new Demo.Entites.Student()
            {
                Name = "amir", Surname = "amiri"
            });
            Console.WriteLine("Done!");
            Console.ReadKey();
        }
コード例 #27
0
 public IHttpActionResult Add(Student student)
 {
     student.Id = Guid.NewGuid().ToString();
     if (!service.IsCityDuplicate(student.City))
     {
         string addedId = service.Add(student);
         return(Ok(true));
     }
     else
     {
         return(Ok(false));
     }
 }
コード例 #28
0
ファイル: StudentTests.cs プロジェクト: codehaks/MySchool
        public async Task Same_Student_Can_Not_Be_Added_To_Class()
        {
            var options = new DbContextOptionsBuilder <PortalDbContext>()
                          .UseInMemoryDatabase(databaseName: "Same_Student_Db")
                          .Options;

            using (var context = new PortalDbContext(options))
            {
                var service = new StudentService(context);
                await service.Add(new Domain.Entities.Student()
                {
                    ClassId = 1, Age = 19, GPA = 3.2f, Name = "Jones"
                });

                await Assert.ThrowsAsync <Exception>(async() =>
                {
                    await service.Add(new Domain.Entities.Student()
                    {
                        ClassId = 1, Age = 18, GPA = 3.0f, Name = "Jones"
                    });
                });
            }
        }
コード例 #29
0
        public int Add(Student model)     //新增
        {
            //首先判断学号是否已存在
            Student entity = dal.GetModel(model.s_Num);

            if (entity != null)
            {
                return(-1);    //学号已存在
            }
            else
            {
                return(dal.Add(model));
            }
        }
コード例 #30
0
ファイル: StudentController.cs プロジェクト: fatihyil/Work
        public IActionResult Add(StudentVM model)
        {
            var studentEntity      = new StudentEntity();
            var studentEntityCount = _studentService.GetStudents().Count;

            studentEntity.Id        = studentEntityCount + 1;
            studentEntity.FirtsName = model.FirtsName;
            studentEntity.LastName  = model.LastName;
            studentEntity.StudentNo = model.StudentNo;
            studentEntity.ClassNo   = model.ClassNo;
            studentEntity.Birthday  = model.Birthday;
            _studentService.Add(studentEntity);
            return(RedirectToAction("Index"));
        }
コード例 #31
0
 public ActionResult AddStudent(StudentEditViewModel student)
 {
     if (!ModelState.IsValid)
     {
         ViewBag.Governate = GovernorateService.GetAll();
         ViewBag.Field     = FieldService.GetAll();
         return(View(student));
     }
     if (student.NeighborhoodId == 0)
     {
         student.NeighborhoodId = null;
     }
     StudentService.Add(student);
     return(RedirectToAction("Index"));
 }