public async Task <ActionResult <Student> > Post([FromBody, Bind("Name", "Email", "Web")] Student entitty) { _db.Students.Add(entitty); await _db.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = entitty.StudentId }, entitty)); }
public async Task <IActionResult> PutTblDrejtimet(int id, TblDrejtimet tblDrejtimet) { if (id != tblDrejtimet.DrejtimetId) { return(BadRequest()); } _context.Entry(tblDrejtimet).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblDrejtimetExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutStudent([FromRoute] Guid id, [FromBody] Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.Id) { return(BadRequest()); } _context.Entry(student).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create(int?id, Student studentmodel, IFormFile FileUrl) { if (ModelState.IsValid) { string dirPath = Path.Combine(_hostingEnvironment.WebRootPath, @"uploads\"); var fileName = Guid.NewGuid().ToString().Replace("-", "") + "_" + FileUrl.FileName; using (var fileStream = new FileStream(dirPath + fileName, FileMode.Create)) { await FileUrl.CopyToAsync(fileStream); } studentmodel.CreatedDate = DateTime.Now; Student student = new Student(); student.StudentNo = studentmodel.StudentNo; student.StudentName = studentmodel.StudentName; student.StudentSurname = studentmodel.StudentSurname; student.StudentEmail = studentmodel.StudentEmail; student.StudentTelNo = studentmodel.StudentTelNo; student.ImageUrl = fileName; student.Content = studentmodel.Content; student.CreatedDate = studentmodel.CreatedDate; student.DepartmentId = studentmodel.DepartmentId; _context.Student.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(studentmodel)); }
public async Task <IActionResult> PutTblLendet(int id, TblLendet tblLendet) { if (id != tblLendet.LendetId) { return(BadRequest()); } _context.Entry(tblLendet).State = EntityState.Modified; try { await _context.TblLendet .Include(i => i.Drejtimi) .FirstOrDefaultAsync(i => i.DrejtimiId == id); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblLendetExists(id)) { return(NotFound("Lenda nuk u gjet!")); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <StudentDto> > Put([FromBody] StudentDto studentDto, CancellationToken token) { var entity = _mapper.Map <Student>(studentDto); _context.Update(entity); await _context.SaveChangesAsync(); return(studentDto); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Age,Gender")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,Nume,Prenume,An,Facultate,Camera,Etaj,Sex,TaxaAchitata")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] AspNetUser aspNetUser) { if (ModelState.IsValid) { _context.Add(aspNetUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(aspNetUser)); }
public async Task <IActionResult> Create([Bind("Id,Name,NormalizedName,ConcurrencyStamp")] AspNetRole aspNetRole) { if (ModelState.IsValid) { _context.Add(aspNetRole); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(aspNetRole)); }
public async Task <IActionResult> Create([Bind("Id,DepartmentName")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("id,first_name,last_name")] Students students) { if (ModelState.IsValid) { _context.Add(students); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(students)); }
//add a student to the set public async Task <IHttpActionResult> Post(Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Students.Add(student); await db.SaveChangesAsync(); return(Created(student)); }
public async Task <IActionResult> Create([Bind("Id,Name,StuID,DepartmentId")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", student.DepartmentId); return(View(student)); }
public async Task <ActionResult> Create([Bind(Include = "COURSE_ID,NAME")] Course course) { if (ModelState.IsValid) { db.Course.Add(course); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(course)); }
public async Task <IActionResult> Create([Bind("UserId,RoleId")] AspNetUserRole aspNetUserRole) { if (ModelState.IsValid) { _context.Add(aspNetUserRole); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.AspNetRoles, "Id", "Id", aspNetUserRole.RoleId); ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUserRole.UserId); return(View(aspNetUserRole)); }
public async Task <ActionResult> Create([Bind(Include = "STUDENT_ID,NAME,LASTNAME,AGE,COURSE_ID")] Student student) { if (ModelState.IsValid) { db.Student.Add(student); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.COURSE_ID = new SelectList(db.Course, "COURSE_ID", "NAME", student.COURSE_ID); return(View(student)); }
public async Task <int> Handle(StudentCreateRequest request, CancellationToken cancellationToken) { var entity = await _context.Student.AddAsync(_mapper.Map <Features.CreateStudent.StudentCreateModel, Data.Models.Student>(request.Model), cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(entity.Entity.Id); }
public async Task <IActionResult> Create(int?id, Student studentmodel) { if (ModelState.IsValid) { Student student = new Student(); student.StudentName = studentmodel.StudentName; student.StudentSurname = studentmodel.StudentSurname; student.StudentNo = studentmodel.StudentNo; student.StudentTelNo = studentmodel.StudentTelNo; student.StudentEmail = studentmodel.StudentEmail; student.DepartmentId = studentmodel.DepartmentId; _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(studentmodel)); }
public async Task<int> Handle(GroupCreateRequest request, CancellationToken cancellationToken) { var result = (await _context.Group.AddAsync(new Group() { Name = request.Model.Name, }, cancellationToken)); await _context.SaveChangesAsync(cancellationToken); return result.Entity.Id; }
public IActionResult Delete(int id) { Student student = db.GetStudents.FirstOrDefault(x => x.Id == id); if (student == null) { return(NotFound()); } db.GetStudents.Remove(student); db.SaveChangesAsync(); return(Ok(student)); }
public async Task <Unit> Handle(AttachStudentRequest request, CancellationToken cancellationToken) { await using var uow = await _context.Database.BeginTransactionAsync(cancellationToken); var group = _context.Group.SingleOrDefault(x => x.Id == request.GroupId); if (group == null) { throw new ArgumentNullException($"Group with identifier: {request.GroupId} wasn't found"); } await _context.StudentGroups.AddAsync(new StudentGroups() { GroupId = request.GroupId, StudentId = request.StudentId }); await _context.SaveChangesAsync(cancellationToken); await uow.CommitAsync(cancellationToken); return(new Unit()); }
public async Task Update(Student student) { db.Students.Update(student); await db.SaveChangesAsync(); }