Ejemplo n.º 1
0
        public IActionResult NewStudent([FromForm] StudentModel studentData)
        {
            _studentsRepository.Add(studentData);
            _studentsRepository.SaveChanges();

            return(RedirectToAction("Students"));
        }
        public async Task <IActionResult> AddStudentAsync(AddStudentDTO addStudentDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var studentModel = _mapper.Map <Student>(addStudentDto);
                    studentModel.RegisteredDate = DateTime.Now;
                    await _context.Add(studentModel);

                    var readStudentDto = _mapper.Map <ReadStudentDTO>(studentModel);
                    _log.AddLog(Request, _httpContextAccessor, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "Eshte shtuar nje student i ri");
                    return(Ok(new DataMessage("Studenti eshte regjistruar me sukses!")));
                }
                catch (Exception ex)
                {
                    _log.AddLog(Request, _httpContextAccessor, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "Deshtim ne regjistrimin e nje studenti");
                    return(BadRequest(new DataMessage("Regjistrimi deshtoi " + ex.Message)));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 3
0
 public IActionResult Create(ApplicationUser user)
 {
     //TODO: use a ViewModel instead of ApplicationUser
     if (ModelState.IsValid)
     {
         _usersRepository.Add(user);
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Ejemplo n.º 4
0
        public async Task SetStudents(List <AddStudentDto> models)
        {
            // ....
            foreach (var model in models)
            {
                _studentsRepository.Add(new Students(model.Name, model.Age));
            }

            await _unitOfWork.CommitAsync();
        }
        public async Task Init()
        {
            var options = CreateNewContextOptions();

            _studentRepository = new StudentsRepository(new SampleAppContext(options));

            // var service = new StudentsRepository(context);
            _studentRepository.Add(new Student {
                Id = 1, Email = "*****@*****.**", FristName = "Papavoisi", LastName = "Jean"
            });
            _studentRepository.Add(new Student {
                Id = 2, Email = "*****@*****.**", FristName = "Garden", LastName = "Pierre"
            });
            _studentRepository.Add(new Student {
                Id = 3, Email = "*****@*****.**", FristName = "Derosi", LastName = "Ronald"
            });

            await _studentRepository.Save();
        }
        public async Task <IActionResult> Create([Bind("Id,Email,FristName,LastName")] Student student)
        {
            if (ModelState.IsValid)
            {
                _studentsRepository.Add(student);
                await _studentsRepository.Save();

                return(RedirectToAction("Index"));
            }
            return(View(student));
        }
Ejemplo n.º 7
0
        public async Task <MessageModel <string> > Post([FromBody] Students Students)
        {
            var data = new MessageModel <string>();

            var id = await _iStudentsRepository.Add(Students);

            data.success = id > 0;
            if (data.success)
            {
                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> AddAsync(AddStudentDTO model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.Notification = new SuccessResult(false, "All fields are required!");
                    return(View(model));
                }
                var result = await _studentsRepository.Add(model);

                if (result.Item1)
                {
                    TempData["SuccessResultF"] = result.Item1;
                    TempData["SuccessResultM"] = result.Item2;

                    return(RedirectToAction("Index", "Students"));
                }
                else
                {
                    ViewBag.Notification = new SuccessResult((bool)result.Item1, (string)result.Item2);
                    model.Index          = "";

                    var deps     = _departamentsRepository.GetAll();
                    var statuses = _statusRepository.GetAll();

                    await Task.WhenAll(deps, statuses);

                    ViewBag.DepartmentId = new SelectList(deps.Result.Item2, "Id", "DepartmentName");
                    ViewBag.StatusId     = new SelectList(statuses.Result.Item2, "Id", "Name");

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> AddStudentAsync(AddStudentDto addStudentDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var studentModel = _mapper.Map <Student>(addStudentDto);
                    await _context.Add(studentModel);

                    var readStudentDto = _mapper.Map <ReadStudentDto>(studentModel);

                    return(Ok("Studenti eshte regjistruar me sukses!"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new DataError("Regjistrimi deshtoi " + ex.Message)));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 10
0
 public async Task Add(Students student)
 {
     await _studentsRepository.Add(student);
 }
Ejemplo n.º 11
0
 public JsonResult Post([FromBody] Student value)
 {
     studentsRepository.Add(value);
     persistenceContext.SaveAll();
     return(Json(value));
 }
Ejemplo n.º 12
0
 public void Post([FromBody] Student value)
 {
     repository.Add(value);
 }