Пример #1
0
 public IActionResult Create(Student model)
 {
     if (ModelState.IsValid)
     {
         _student.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Пример #2
0
        public IActionResult Create(StudentCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUloadedFile(model);

                StudentClass newStudent = new StudentClass
                {
                    Name             = model.Name,
                    Email            = model.Email,
                    Gender           = model.Gender,
                    DOB              = model.DOB,
                    Address          = model.Address,
                    Identification   = model.Identification,
                    Nationality      = model.Nationality,
                    Phone            = model.Phone,
                    HealthCondition  = model.HealthCondition,
                    Marital          = model.Marital,
                    NextOfKinName    = model.NextOfKinName,
                    NextOfKinPhone   = model.NextOfKinPhone,
                    NextOfKinAddress = model.NextOfKinAddress,
                    StudentStatus    = model.StudentStatus,
                    AdmissionType    = model.AdmissionType,
                    PhotoPath        = uniqueFileName
                };
                _studentRepo.Add(newStudent);
                return(RedirectToAction("index", new { Id = newStudent.Id }));
            }


            return(View());
        }
Пример #3
0
        public IActionResult OnPost()
        {
            var webRootPath = _hostEnvironment.WebRootPath;
            var files       = HttpContext.Request.Form.Files;

            if (!ModelState.IsValid)
            {
                StudentVM.Department = _deptRepo.GetDepartmentListOfDropDown();
                return(Page());
            }
            else
            {
                var fileName  = Guid.NewGuid().ToString();
                var uploads   = Path.Combine(webRootPath, @"images\photos");
                var extention = Path.GetExtension(files[0].FileName);
                using (var fileStream = new FileStream(Path.Combine(uploads, fileName + extention), FileMode.Create))
                {
                    files[0].CopyTo(fileStream);
                }
                StudentVM.Student.Image = @"\images\photos\" + fileName + extention;
                _studentRepo.Add(StudentVM.Student);
                _studentRepo.Save();
                return(RedirectToPage("Details"));
            }
        }
Пример #4
0
        public ActionResult Add()
        {
            Student student = new Student();

            student.StudentId = 1;
            student.Name      = "ABC";
            _IStudent.Add(student);
            return(Ok(true));
        }
        public async Task <ActionResult <Student> > PostStudent(Student student)
        {
            await Task.Run(() => _studentrepo.Add(student));

            //_context.Students.Add(student);
            //await _context.SaveChangesAsync();
            var userViewModel = _mapper.Map <Student, StudentViewModel>(student);

            return(CreatedAtAction("GetStudent", new { id = student.StudentID }, userViewModel));
        }
Пример #6
0
 public MessageModel <Student> Add(Student student)
 {
     if (IStudent.Add(student))
     {
         return(new MessageModel <Student> {
             Success = true, Msg = "操作成功"
         });
     }
     else
     {
         return(new MessageModel <Student> {
             Success = false, Msg = "操作失败"
         });
     }
 }
Пример #7
0
        public IActionResult AddStudent(StudentDtoWrite aStudent)
        {
            Student myStudent = _mapper.Map <Student>(aStudent);

            if (_repo.FindByCode(myStudent) == null)
            {
                myStudent = _repo.Add(myStudent);
                var myResponse = _mapper.Map <StudentDtoWrite>(myStudent);
                return(Ok(myResponse));
            }
            else
            {
                return(BadRequest("Student already exists"));
            }
        }
Пример #8
0
        public async Task <IActionResult> AddKidSubmit(AddKidModel model, int kidId, IFormFile avatarImage)
        {
            if (ModelState.IsValid && model.ChoosenSchoolClassId > 0)
            {
                var user = await GetCurrentUserAsync();

                if (user is ParentAccount parentAccount)
                {
                    var newStudent = new Student()
                    {
                        Name        = model.StudentName,
                        LastName    = parentAccount.LastName,
                        SchoolClass = _schoolClasses.GetById(model.ChoosenSchoolClassId)
                    };

                    if (avatarImage != null)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await avatarImage.CopyToAsync(memoryStream);

                            newStudent.AvatarImage = memoryStream.ToArray();
                        }
                    }

                    _students.Add(newStudent);
                    _parentAccounts.AddNewStudent(parentAccount.Id, newStudent);

                    return(RedirectToAction("Index"));
                }
            }
            var student = _students.GetById(kidId);

            if (student != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await avatarImage.CopyToAsync(memoryStream);

                    student.AvatarImage = memoryStream.ToArray();
                }

                _students.UpdateImage();
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Error", "Home"));
        }
Пример #9
0
 public MessageModel <Student> Add(Student entity)
 {
     if (IService.Add(entity))
     {
         return new MessageModel <Student> {
                    Success = true, Msg = "操作成功"
         }
     }
     ;
     else
     {
         return new MessageModel <Student> {
                    Success = false, Msg = "操作失败"
         }
     };
 }
Пример #10
0
        public async Task <ActionResult> Create(Student student)
        {
            if (ModelState.IsValid)
            {
                string ImageUrl = "";

                var files = HttpContext.Request.Form.Files;
                foreach (var Image in files)
                {
                    if (Image != null && Image.Length > 0)
                    {
                        var file = Image;

                        var upload = Path.Combine(_environment.WebRootPath, "images");

                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString().Replace("-", "") + file.FileName;

                            using (var fileStream = new FileStream(Path.Combine(upload, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                ImageUrl = fileName;
                            }
                        }
                    }
                }

                var data = new Student()
                {
                    Name      = student.Name,
                    Address   = student.Address,
                    UrlImage  = student.UrlImage,
                    CellPhone = student.CellPhone,
                    Email     = student.Email
                };

                _db.Add(data);
                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction("Index"));
        }
Пример #11
0
        public static void BaseUsage()
        {
            ContainerBuilder builder = new ContainerBuilder();

            /*
             * 这是一种建造者模式的应用,即要通过autofac来注入的类型是不确定的
             * 所以要通过依次将需要注入的类型注册到ContainerBuilder上,
             * 这之后就可直接创建容器来使用。
             */
            builder.RegisterType <Calculator>().As <ICalculator>();
            builder.RegisterType <Student>().As <IStudent>();
            IContainer container = builder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                IStudent calc = scope.Resolve <IStudent>();
                Console.WriteLine(calc.Add(1, 2));
            }
        }
        public IActionResult Post([FromBody] Domain.Entities.Student entity)
        {
            try
            {
                var result = _student.Add(entity);

                _unitOfWork.Commit();

                if (!result.Errors.Any())
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest(result.Errors));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("Id,Firstname,Lastname,Address,Gender,StudentNumber,DateofBirth,ClassId")] CreateStudentViewModel model)
        {
            model.CreatedDate   = DateTime.UtcNow.Date;
            model.ModifiedDate  = DateTime.UtcNow.Date;
            model.StudentNumber = "STN" + DateTime.Now.Year.ToString() + model.StudentNumber;
            if (!stu.IfExists(model.StudentNumber, null))
            {
                if (ModelState.IsValid)
                {
                    var _student = new Student();
                    _student.Lastname      = model.Lastname.ToUpper();
                    _student.Firstname     = model.Firstname.ToUpper();
                    _student.Gender        = model.Gender;
                    _student.Address       = model.Address;
                    _student.CreatedDate   = model.CreatedDate;
                    _student.ModifiedDate  = model.ModifiedDate;
                    _student.StudentNumber = model.StudentNumber;
                    _student.DateofBirth   = model.DateofBirth;
                    _student.IsEnrolled    = true;
                    stu.Add(_student);
                    await stu.SaveChangesAsync();

                    var en = new Enrollement();
                    en.StudentID       = _student.Id;
                    en.ClassID         = model.ClassId;
                    en.EnrollementDate = DateTime.UtcNow.Date;
                    enr.Add(en);
                    await enr.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }

                return(PartialView(model));
            }

            return(PartialView(model));
        }
Пример #14
0
 public bool Add(Student entity)
 {
     return(iStudent.Add(entity));
 }
Пример #15
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Ncu.jsj.Model.Student model)
 {
     return(dal.Add(model));
 }
        public async Task <ActionResult <StudentModel> > PostStudent(StudentModel student)
        {
            var createdStudent = await _student.Add(student);

            return(Ok(createdStudent));
        }
Пример #17
0
 public bool Add(E_Model.Student model)
 {
     return(dal.Add(model));
 }
Пример #18
0
 public void Add(Student student)
 {
     studentRepository.Add(student);
 }