public ActionResult create(NewStudent model) { if (ModelState.IsValid) { var user = new ApplicationUser(); user.UserName = model.Username; user.Name = model.Name; user.Surname = model.Surname; user.Group = model.Group; user.Group1 = model.Group1; user.Sinif = model.Sinif; user.PhoneNumber = model.PhoneNumber; user.Parent = model.Parent; var result = userManager.Create(user, model.Password); if (result.Succeeded) { return(RedirectToAction("index")); } else { foreach (var item in result.Errors) { ModelState.AddModelError("", item); } } } return(View(model)); }
private void createToolStripMenuItem1_Click(object sender, EventArgs e) { paneldetails.Controls.Clear(); NewStudent newStudent = new NewStudent(user); paneldetails.Controls.Add(newStudent); }
public ActionResult CreateStudent(NewStudent viewModel) { var db = new DatabaseContext(); var schoolhouse = db.SchoolHouses .FirstOrDefault(schoolhouse => schoolhouse.Id == viewModel.SchoolHouseId); if (schoolhouse == null) { return(NotFound()); } else { var student = new Student { FullName = viewModel.FullName, PlaysQuidditch = viewModel.PlaysQuidditch, SchoolHouseId = viewModel.SchoolHouseId }; db.Students.Add(student); db.SaveChanges(); var rv = new CreatedStudent { Id = student.Id, PlaysQuidditch = student.PlaysQuidditch, SchoolHouseId = student.SchoolHouseId }; return(Ok(rv)); } }
private void button1_Click(object sender, EventArgs e) { NewStudent newStudent = new NewStudent(); newStudent.Show(); this.Hide(); }
public ActionResult CreateStudent(NewStudent vm) { var db = new DatabaseContext(); student.Id = 0; var student = db.Students.FirstOrDefault(student => student.Id == vm.StudentId); if (student == null) { return(NotFound()); } else { var list = new Student { FullName = vm.FullName, StudentId = vm.StudentId }; db.Students.Add(list); db.SaveChanges(); var rv = new CreatedStudent { Id = list.Id, FullName = list.FullName, StudentId = list.StudentId }; return(Ok(rv)); } }
public async Task <ActionResult <Student> > PostStudent(NewStudent student) { // if (StudentExists(student.Username)) // { // return BadRequest("Student already exists in the database"); // } try { string userId = MicrosoftLearnUtil.GetUserId(student.Username); Student newStudent = new Student { FirstName = student.FirstName, LastName = student.LastName, School = student.School, Username = student.Username, Email = student.Email, CreateDate = DateTime.Now, UserId = userId, Score = MicrosoftLearnUtil.GetXP(userId) }; _context.Student.Add(newStudent); await _context.SaveChangesAsync(); return(CreatedAtAction("GetStudent", new { id = newStudent.Id }, newStudent)); } catch (WebException) { return(BadRequest("Unable to find user, please check the username")); } }
public ActionResult CreateStudent(NewStudent vm) { var db = new DatabaseContext(); student.Id = 0; var student = db.Students.FirstOrDefault(student => student.Id == vm.StudentId); }
public ActionResult DeleteConfirmed(int id) { NewStudent newStudent = db.NewStudents.Find(id); db.NewStudents.Remove(newStudent); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CreateStudent(NewStudent vm) { var db = new DatabaseContext(); student.Id = 0; db.Students.Add(student); db.SaveChanges(); return(Ok(student)); }
private void NuevoEstudiante_Click(object sender, EventArgs e) { NewStudent AddStudentForm = new NewStudent(datosBin); AddStudentForm.ShowDialog(); datosBin.RecargarEstudiantes(); TablaEstudiantes.DataSource = datosBin.Estudiantes; TablaEstudiantes.Refresh(); }
public ActionResult Edit([Bind(Include = "ID,Name,Surname,Otch,PasportSer,PasportNumber,ZachetNumber,Sex,Birthday,Town")] NewStudent newStudent) { if (ModelState.IsValid) { db.Entry(newStudent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(newStudent)); }
public ActionResult Create([Bind(Include = "ID,Name,Surname,Otch,PasportSer,PasportNumber,ZachetNumber,Sex,Birthday,Town")] NewStudent newStudent) { if (ModelState.IsValid) { db.NewStudents.Add(newStudent); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(newStudent)); }
public ActionResult _SaveNewStudentAjaxEditing(int id) { var student = NewStudentListOps._GetOneNewStudent(id); TryUpdateModel(student); NewStudent s = db.NewStudents.Find(id); s = student.UpdateNewStudentModel(s); db.Entry(s).State = EntityState.Modified; db.SaveChanges(); return(_OrgVolunteerList(s.Organization.Id)); }
// GET: NewStudents/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NewStudent newStudent = db.NewStudents.Find(id); if (newStudent == null) { return(HttpNotFound()); } return(View(newStudent)); }
public ActionResult CreateStudent(NewStudent newStudent) { try { CheckModelState(ModelState, "Students.CreateStudent"); newStudent.Password = AESCrypt.EncryptString(newStudent.Password, "SSWSecretKey"); var Mapper = new MapperConfiguration(cfg => cfg.CreateMap <NewStudent, Students>()).CreateMapper(); Students student = Mapper.Map <Students>(newStudent); var Id = DBHelper.Instance.CreateStudent(student); return(Json(new { success = "Студент успешно добавлен", Id = Id })); } catch (Exception ex) { return(Json(new { errors = ex.Message })); } }
public void When_TriggerFires_Then_CorrectObjectReturned() { // Arrange var inputStudent = new NewStudent { Name = "UnitTest Student" }; // Act var httpResponse = PushToCosmosDbFn.AddStudent(inputStudent, out StudentCosmosModel student); // Assert (HTTP Response) var createdResult = httpResponse.Should().BeOfType <CreatedResult>().Subject; createdResult.Location.Should().Be($"api/students/{student.studentId}"); student.Should().Be(createdResult.Value); student.name.Should().Be("UnitTest Student"); }
public static async Task <IActionResult> OnAddStudentAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "students")] HttpRequest req) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); NewStudent newStudent = JsonConvert.DeserializeObject <NewStudent>(requestBody); if (string.IsNullOrWhiteSpace(newStudent.Name)) { return(new BadRequestObjectResult("Missing student name.")); } var student = new Student(Guid.NewGuid(), newStudent.Name); // TODO: Save it return(new CreatedResult($"api/students/{student.Id}", student)); }
public ActionResult CreateStudent(NewStudent viewModel) { var db = new DatabaseContext(); var schoolhouse = db.SchoolHouses .FirstOrDefault(schoolhouse => schoolhouse.Id == viewModel.SchoolHouseId); if (schoolhouse == null) { return(NotFound()); } else { var student = new Student { FullName = viewModel.FullName, PlaysQuidditch = viewModel.PlaysQuidditch, }; } }
public ActionResult CreateStudent(NewStudent vm) { var db = new DatabaseContext(); student.Id = 0; var student = db.Students.FirstOrDefault(student => student.Id == vm.StudentId); if (student == null) { return(NotFound()); } else { var list = new Student { FullName = vm.FullName, StudentId = vm.StudentId }; } }
public ActionResult CreateStudent(NewStudent viewModel) { var db = new DatabaseContext(); var schoolhouse = db.SchoolHouses .FirstOrDefault(schoolhouse => schoolhouse.Id == viewModel.SchoolHouseId); if (schoolhouse == null) { return(NotFound()); } else { var student = new SchoolHouse { HouseName = viewModel.HouseName, Color = viewModel.Color, SchoolHouseId = viewModel.SchoolHouseId }; } }
public static IActionResult AddStudent( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v2/students")] NewStudent newStudent , [CosmosDB("school", "students", ConnectionStringSetting = "CosmosDbConn")] out StudentCosmosModel student) { student = null; if (string.IsNullOrWhiteSpace(newStudent.Name)) { return(new BadRequestObjectResult("Student name required.")); } var rand = new Random(); student = new StudentCosmosModel { studentId = rand.Next(1000, 900000), name = newStudent.Name }; return(new CreatedResult($"api/students/{student.studentId}", student)); }
public void NewStudent() { _newStudent = new NewStudent(); _main.Content = _newStudent; }
public IActionResult CreateStudent(NewStudent student) { return(Ok(service.AddStudent(student))); }
public string AddStudent(NewStudent student) { if (student.Studies == null || student.FirstName == null || student.LastName == null || student.Birthdate == null || student.IndexNumber == null) { return("Brak danych"); } using (SqlConnection con = new SqlConnection(conString)) using (SqlCommand com = new SqlCommand()) { con.Open(); SqlTransaction trans = con.BeginTransaction("SampleTransaction"); com.Connection = con; com.Transaction = trans; try { com.CommandText = "select IndexNumber from Student;"; SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { if (student.IndexNumber == dr["IndexNumber"].ToString()) { return("Podany numer indexu juz istnieje"); } } com.CommandText = "select * from Studies inner join Enrollment on Studies.IdStudy = Enrollment.IdStudy where Name = @studies and Semester = 1;"; com.Parameters.AddWithValue("studies", student.Studies); dr.Close(); dr = com.ExecuteReader(); if (!dr.Read()) { com.CommandText = "insert into Studies(IdStudy, Name) " + "values((select max(IdStudy) from Studies) + 1, @studies) " + "insert into Enrollment(IdEnrollment, Semester, IdStudy, StartDate) " + "values((select max(IdEnrollment) from Enrollment) + 1, 1, (select IdStudy from Studies where Name = @studies), GETDATE())"; dr.Close(); com.ExecuteNonQuery(); } com.CommandText = "insert into Student(IndexNumber, FirstName, LastName, BirthDate, IdEnrollment) " + "values(@indexnumber, @firstname, @lastname, @birthdate, (select IdEnrollment from Enrollment where IdStudy = (select IdStudy from Studies where Name = @studies and Semester = 1)));"; com.Parameters.AddWithValue("indexnumber", student.IndexNumber); com.Parameters.AddWithValue("firstname", student.FirstName); com.Parameters.AddWithValue("lastname", student.LastName); com.Parameters.AddWithValue("birthdate", student.Birthdate); dr.Close(); com.ExecuteNonQuery(); trans.Commit(); return("Dodano nowego studenta"); } catch (Exception ex) { try { trans.Rollback("Wystapili bledy"); } catch (Exception ex2) { } } return("Wystapili bledy"); } }