예제 #1
0
        public async Task <IActionResult> Post([FromBody] StudentVM objstudent)
        {
            if (ModelState.IsValid)
            {
                // Todo is ok
                _message = await Task.Run(() => _student.Create(objstudent));

                if (_message.status_item)
                {
                    return(Ok(_message.details));
                }
                else
                {
                    return(StatusCode(401, _message.Res()));
                }
            }
            else
            {
                var mes = string.Join(" | ", ModelState.Values
                                      .SelectMany(v => v.Errors)
                                      .Select(e => e.ErrorMessage));

                _message.details = mes;
                return(BadRequest(_message.Res()));
            }
        }
예제 #2
0
        public async Task <IActionResult> Create(Student model, bool SaveAndCountinue = false)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var obj = new Student()
            {
                Id         = model.Id,
                FullName   = model.FullName,
                Age        = model.Age,
                DateCreate = model.DateCreate,
                IsDelete   = model.IsDelete
            };
            // thuc hientheem mới
            var result = await StudentService.Create(obj);

            if (result.isSuccess)
            {
                if (SaveAndCountinue)
                {
                    TempData["Success"] = "Thêm mới thành công";
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
 public bool Create([FromBody] Student std)
 {
     if (student.Any(s => s.StudentFirstName == std.StudentFirstName && s.StudentLastName == std.StudentLastName && s.Contact == std.Contact))
     {
         return(false);
     }
     else
     {
         student.Create(std);
         return(true);
     }
 }
예제 #4
0
        public ResultHandler <StudentDto> Create(StudentDto studentDto)
        {
            ResultHandler <StudentDto> resultHandler = new ResultHandler <StudentDto>();

            try
            {
                Student student = _student.Create(studentDto.FirstName, studentDto.LastName, studentDto.Description, studentDto.Height, studentDto.PayRate, studentDto.PrepaidMoney, studentDto.IsActive);
                _studentRepository.Create(student);
                resultHandler.Data = AutoMapper.Mapper.Map <Student, StudentDto>(student);
            }
            catch (Exception ex)
            {
                resultHandler.Errors.Add(ex.Message);
            }

            return(resultHandler);
        }
예제 #5
0
        public ActionResult <CrudAngular.Models.Student> PostStudents(CrudAngular.Models.Student student)
        {
            try
            {
                _student.Create(student);
            }
            catch (DbUpdateException)
            {
                if (_student.Any(e => e.Id == student.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetStudents", new { id = student.Id }, student));
        }
예제 #6
0
        public IActionResult Student(Student student)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            if (ModelState.IsValid)
            {
                StudentRepository.Create(student);


                var routeValues = new RouteValueDictionary {
                    { "ID", student.StId },
                    { "name", student.StName }
                };
                return(RedirectToAction("Create", "Admission1", routeValues));
            }

            else
            {
                return(View(student));
            }
        }
 public async Task CreateStudent(int id, string name, IEnumerable <Course> courses)
 {
     var person  = new Student();
     var student = _studentService.Create(person);
     await _context.SaveChangesAsync();
 }