public bool InsertStudentRecord(AddStudentModel model) { using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { SqlCommand command = new SqlCommand("AddNewStudent", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Name", model.Name); command.Parameters.AddWithValue("@Email", model.Email); command.Parameters.AddWithValue("@StudentId", model.StudentId); command.Parameters.AddWithValue("@Username", model.Username); command.Parameters.AddWithValue("@Password", model.Password); connection.Open(); try { int i = command.ExecuteNonQuery(); connection.Close(); if (i > 0) { return(true); } } catch (Exception e) { return(false); } } return(false); }
public async Task <IDataResult <long> > Add(AddStudentModel addStudentModel) { var validation = new AddStudentModelValidator().Valid(addStudentModel); if (!validation.Success) { return(new ErrorDataResult <long>(validation.Message)); } StudentDomain domain = new StudentDomain(DatabaseUnitOfWork, StudentRepository, CourseRepository); var student = domain.ConvertToStudentEntity(addStudentModel); string errorMessage = await domain.ApplyBusinessRules(student); if (!string.IsNullOrWhiteSpace(errorMessage)) { return(new ErrorDataResult <long>(errorMessage)); } await StudentRepository.AddAsync(student); await DatabaseUnitOfWork.SaveChangesAsync(); return(new SuccessDataResult <long>(student.StudentId)); }
public JsonResult AddStudent(AddStudentModel data) { var students = db.Database.SqlQuery <GetGroupsDataModel>("EXEC GetStudentGroupData @p0", data.GroupID).ToList(); var student = students.Find(x => x.WorkerID == data.WorkerID); string result = "Exist"; if (student == null) { try { var query = new StringBuilder("EXEC AddStudent @workerId = ") .Append(data.WorkerID) .Append(", @groupId = ") .Append(data.GroupID) .Append(";"); db.Database.ExecuteSqlCommand(query.ToString()); result = "Added"; } catch (Exception) { result = "Database Failure"; } } return(Json(new { result = result })); }
public ActionResult AddStudent([FromBody] AddStudentModel studentModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = _mapper.Map <AddStudentModel, StudentModel>(studentModel); _istudentservice.AddStudent(model); return(Ok("Success")); }
public ActionResult AddStudent(AddStudentModel model, string returnUrl) { var objUtilities = new Utilities.Utilities(); bool validateInsertTeacherRecord = objUtilities.InsertStudentRecord(model); if (validateInsertTeacherRecord) { return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "UserName or StudentId Already exists."); return(View()); }
public async Task <bool> AddStudentAsync(AddStudentModel profile) { try { DbUser user = new DbUser { UserName = profile.Email /*profile.UserName*/, Email = profile.Email, PhoneNumber = profile.PhoneNumber, }; BaseProfile prof = new BaseProfile { Name = profile.Name, LastName = profile.LastName, Surname = profile.Surname, Adress = profile.Adress, DateOfBirth = Convert.ToDateTime(profile.DateOfBirth), PassportString = profile.PassportString, IdentificationCode = profile.IdentificationCode }; string password = PasswordGenerator.GenerationPassword(); await _userManager.CreateAsync(user, password); await _userManager.AddToRoleAsync(user, "Student"); prof.Id = user.Id; await _context.BaseProfiles.AddAsync(prof); await _context.SaveChangesAsync(); await _context.StudentProfiles.AddAsync(new StudentProfile { Id = prof.Id }); await _context.SaveChangesAsync(); if (profile.GroupId != 0) { await _context.GroupsToStudents.AddAsync(new GroupToStudent { GroupId = profile.GroupId, StudentId = user.Id }); await _context.SaveChangesAsync(); } return(true); } catch (Exception ex) { return(false); } }
public async Task <IDataResult <long> > AddAsync(AddStudentModel addStudentModel) { var validation = new AddStudentModelValidator().Valid(addStudentModel); if (!validation.Success) { return(new ErrorDataResult <long>(validation.Message)); } // TODO: Add dependency injection. IQueueClient queueClient = new QueueClient(Environment.GetEnvironmentVariable("LearningHub_AzureServiceBus"), Environment.GetEnvironmentVariable("LearningHub_QueueName")); var encodedMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(addStudentModel))); await queueClient.SendAsync(encodedMessage); return(new SuccessDataResult <long>("Added to Processing Queue")); }
public IActionResult AddStudent(AddStudentModel addStudentModel) { var veza = db.LabVezbaStudent.FirstOrDefault(x => x.LabVezbaId == addStudentModel.LabId && x.StudentId == addStudentModel.StudentId); if (veza != null) { return(BadRequest()); } veza = new LabVezbaStudent { LabVezbaId = addStudentModel.LabId, StudentId = addStudentModel.StudentId }; db.LabVezbaStudent.Add(veza); db.SaveChanges(); return(Ok()); }
public ActionResult AddStudent(AddStudentModel model) { if (ExtFunctions.checkStudent()) { // check if student is in the set of students returned by query if (!ExtFunctions.worksOnProject(model.projectID)) { return RedirectToAction("Index", "Home"); } } try { var student = db.get_Student_ByEmail(model.StudentEmail).FirstOrDefault(); db.add_Student_to_Project(student.StudentID, model.projectID); return RedirectToAction("AddRemStudents", new { ProjectID = model.projectID }); } catch { return RedirectToAction("AddRemStudents", new { ProjectID = model.projectID }); } }
public IActionResult AddStudent( [Bind(nameof(AddStudentModel.Name), nameof(AddStudentModel.Username), nameof(AddStudentModel.Email))] AddStudentModel model) { if (ModelState.IsValid) { try { model.AddStudent(); model.Response = new ResponseModel("Student Added Successfully", ResponseType.Success); return(RedirectToAction("Index")); } catch (DuplicationException ex) { model.Response = new ResponseModel(ex.Message, ResponseType.Failure); } catch (Exception ex) { model.Response = new ResponseModel("Failed to Add Student", ResponseType.Failure); } } return(View(model)); }
public IActionResult AddStudent(AddStudentModel model) { if (!ModelState.IsValid) { TempData["warning"] = "Invalid"; return(View()); } if (_membersService.GetMember(model.MemberModel.Email) != null) { TempData["warning"] = "Student already exists"; return(RedirectToAction("Index", "Assignments")); } string randomPassword = GenerateRandomPassword(); var user = new ApplicationUser { UserName = model.MemberModel.Email, Email = model.MemberModel.Email }; var result = _userManager.CreateAsync(user, randomPassword); if (result.Result.Succeeded) { _userManager.AddToRoleAsync(user, "Student"); EmailModel em = new EmailModel(); em.Email = "*****@*****.**"; em.To = model.MemberModel.Email; model.EmailModel = em; using (MailMessage mm = new MailMessage(model.EmailModel.Email, model.EmailModel.To)) { mm.Subject = "Login Credentials"; mm.Body = "You have been assigned an account. Username is: " + em.To + " and your password is : " + randomPassword; mm.IsBodyHtml = false; using (SmtpClient smtp = new SmtpClient()) { smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(model.EmailModel.Email, "74bf*XBG^0ga"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); ViewBag.Message = "Email sent"; } } model.MemberModel.TeacherEmail = User.Identity.Name; Tuple <string, string> keys = CryptographicHelper.GenerateAsymmetricKeys(); model.MemberModel.PublicKey = keys.Item1; model.MemberModel.PrivateKey = keys.Item2; _membersService.AddMember(model.MemberModel); } return(RedirectToAction("Index", "Assignments")); }
public IActionResult AddStudent() { var model = new AddStudentModel(); return(View(model)); }
public StudentEntity ConvertToStudentEntity(AddStudentModel addStudentModel) { return(new StudentEntity { Name = addStudentModel.Name, Age = addStudentModel.Age, CourseId = addStudentModel.CourseId }); }
public async Task <IActionResult> AddAsync(AddStudentModel addUserModel) { var result = await StudentService.AddAsync(addUserModel); return(new ActionIResult(result)); }