Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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"));
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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 });
            }
        }
Exemplo n.º 10
0
 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));
 }
Exemplo n.º 11
0
        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"));
        }
Exemplo n.º 12
0
        public IActionResult AddStudent()
        {
            var model = new AddStudentModel();

            return(View(model));
        }
Exemplo n.º 13
0
 public StudentEntity ConvertToStudentEntity(AddStudentModel addStudentModel)
 {
     return(new StudentEntity {
         Name = addStudentModel.Name, Age = addStudentModel.Age, CourseId = addStudentModel.CourseId
     });
 }
Exemplo n.º 14
0
        public async Task <IActionResult> AddAsync(AddStudentModel addUserModel)
        {
            var result = await StudentService.AddAsync(addUserModel);

            return(new ActionIResult(result));
        }