public async Task <ActionResult> Register([Bind(Include = "StudentCode,StudentEmail,StudentName,StudentFaculty,NationalID,Password,ConfirmPassword,LevelName,PhoneNumber")] Register register)
        {
            if (ModelState.IsValid)
            {
                if (register.StudentName == null || register.StudentFaculty == null)
                {
                    ViewBag.ModelErrors = "كود الطالب غير صحيح";
                    ViewBag.LevelName   = new SelectList(levels, "LevelName", "LevelName", register.LevelName);
                    return(View(register));
                }
                CP_Registration registration = new CP_Registration();
                var             pass         = HashHelper.Encrypt(register.Password);
                var             registered   = db.CP_Registration.Where(s => s.StudentCode == register.StudentCode || s.StudentEmail == register.StudentEmail || s.Password == pass || s.NationalID == register.NationalID).FirstOrDefault();
                if (registered != null)
                {
                    if (registered.StudentCode == register.StudentCode)
                    {
                        ViewBag.ModelErrors = "كود الطالب مسجل مسبقا";
                    }
                    else if (registered.Password == pass)
                    {
                        ViewBag.ModelErrors = "كلمة المرور مسجل مسبقا";
                    }
                    else if (registered.StudentEmail == register.StudentEmail)
                    {
                        ViewBag.ModelErrors = "الايميل مسجل مسبقا";
                    }
                    else if (registered.NationalID == register.NationalID)
                    {
                        ViewBag.ModelErrors = "الرقم القومى مسجل مسبقا";
                    }
                    else
                    {
                        ViewBag.ModelErrors = "حدث خطا ما اثناء معالجة طلبك";
                    }
                    ViewBag.LevelName = new SelectList(levels, "LevelName", "LevelName", register.LevelName);
                    return(View(register));
                }
                var hashedpassword = HashHelper.Encrypt(register.Password);
                registration.StudentCode    = register.StudentCode;
                registration.StudentEmail   = register.StudentEmail;
                registration.StudentName    = register.StudentName;
                registration.StudentFaculty = register.StudentFaculty;
                registration.NationalID     = register.NationalID;
                registration.Password       = hashedpassword;
                registration.LevelName      = register.LevelName;
                registration.PhoneNumber    = register.PhoneNumber;
                db.CP_Registration.Add(registration);
                db.SaveChanges();
                var activationcode = HashHelper.Encrypt(register.StudentCode);
                await MailHelper.SendActivationMail(register.StudentEmail, Request.Url.Scheme, Request.Url.Host, Request.Url.Port.ToString(), activationcode);

                ViewBag.Message = "تم ارسال رابط التفعيل على البريد الالكترونى";
                return(View("Message"));
            }
            ViewBag.LevelName = new SelectList(levels, "LevelName", "LevelName", register.LevelName);
            return(View(register));
        }
Exemple #2
0
        public ActionResult TarbeaRegistration([Bind(Include = "DurationID,NationalID,StudentName,StudentFacuty,StudentUniversity,LevelName,Section,Address,TelephoneNumber,PhoneNumber")] Tarbea tarbeaRegistration)
        {
            int courseId = SystemHelper.GetCourseObjectId(tarbeaRegistration);
            var course   = db.CP_Course.Find(courseId);

            if (course == null)
            {
                return(HttpNotFound());
            }
            if (ModelState.IsValid)
            {
                var studentRegistration = (int)Session["UserId"];
                var student             = db.CP_Registration.Find(studentRegistration);
                if (student != null)
                {
                    var duration = db.CP_Duration.Find(tarbeaRegistration.DurationID);
                    if (duration.NumberRolled == duration.MaxCapacity - 1)
                    {
                        duration.Active = false;
                    }
                    duration.NumberRolled++;
                    duration.SerialFrom++;
                    var serial = duration.SerialFrom;
                    db.Entry(duration).State = EntityState.Modified;
                    student.StudentSection   = tarbeaRegistration.Section;
                    student.StudentAddress   = tarbeaRegistration.Address;
                    student.TelephoneNumber  = tarbeaRegistration.TelephoneNumber;
                    student.UniversityName   = tarbeaRegistration.StudentUniversity;
                    CP_RegisteredCourse registeredCourse = new CP_RegisteredCourse
                    {
                        CourseID     = course.ID,
                        RegisteredID = student.ID,
                        DurationID   = tarbeaRegistration.DurationID,
                        SerialNumber = serial
                    };
                    student.CP_RegisteredCourse.Add(registeredCourse);
                    db.Entry(student).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("CourseDetails", new { id = course.ID }));
                }
                return(HttpNotFound());
            }
            var durations = SystemHelper.GetActiveCourseDuration(course.ID);

            ViewBag.DurationID = new SelectList(durations, "ID", "Name", tarbeaRegistration.DurationID);
            return(View(tarbeaRegistration));
        }
Exemple #3
0
        public static void CreateAdminUser()
        {
            CP_User user = new CP_User
            {
                Name         = WebConfigurationManager.AppSettings["UserName"],
                Email        = WebConfigurationManager.AppSettings["UserEmail"],
                Password     = HashHelper.Encrypt(WebConfigurationManager.AppSettings["UserPassword"]),
                CreationDate = DateTime.Now
            };
            var us = db.CP_User.Where(u => u.Name == user.Name || u.Password == user.Password).FirstOrDefault();

            if (us == null)
            {
                db.CP_User.Add(user);
                db.SaveChanges();
            }
        }
Exemple #4
0
 public ActionResult Create([Bind(Include = "CourseId,CourseImage,CourseName,GenderAllowed,CourseDetails")] Course course, HttpPostedFileBase Image)
 {
     if (ModelState.IsValid)
     {
         if (Image != null && Image.ContentLength > 0)
         {
             var allowedExtensions = new[] { ".jpg", ".jpeg" };
             var extension         = Path.GetExtension(Image.FileName);
             var fileExtension     = extension.ToLower();
             if (allowedExtensions.Contains(fileExtension))
             {
                 var    uniqe = Guid.NewGuid();
                 string path  = Path.Combine(Server.MapPath("~/Uploads"), uniqe + extension);
                 Image.SaveAs(path);
                 course.CourseImage = uniqe + extension;
             }
             else
             {
                 ViewBag.ModelErrors   = "يجب ان يكون الفايل بامتداد .jpg , .jpeg";
                 ViewBag.GenderAllowed = new SelectList(db.CP_Gender, "ID", "Name", course.GenderAllowed);
                 return(View(course));
             }
         }
         CP_Course cours = new CP_Course
         {
             Name         = course.CourseName,
             Gender       = course.GenderAllowed,
             Details      = course.CourseDetails,
             Image        = course.CourseImage,
             CreationDate = DateTime.Now,
             CreatorID    = Int32.Parse(Session["UserId"].ToString())
         };
         db.CP_Course.Add(cours);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GenderAllowed = new SelectList(db.CP_Gender, "ID", "Name", course.GenderAllowed);
     return(View(course));
 }
Exemple #5
0
 public ActionResult Create([Bind(Include = "UserName,UserEmail,IsAdmin,CoursePrivilege,UserPassword")] User user)
 {
     if (ModelState.IsValid)
     {
         var password = HashHelper.Encrypt(user.UserPassword);
         var ouser    = db.CP_User.Where(u => u.Name == user.UserName || u.Password == password).FirstOrDefault();
         if (ouser != null)
         {
             if (ouser.Password == user.UserPassword)
             {
                 ViewBag.ModelErrors = "كلمة المرور موجود مسبقا";
             }
             else
             {
                 ViewBag.ModelErrors = "اسم المستخدم موجود مسبقا";
             }
             ViewBag.CoursePrivilege = new SelectList(db.CP_Course, "ID", "Name", user.CoursePrivilege);
             return(View(user));
         }
         CP_User us = new CP_User
         {
             Name         = user.UserName,
             Email        = user.UserEmail,
             CreationDate = DateTime.Now,
             CreatorID    = Int32.Parse(Session["UserId"].ToString())
         };
         if (!user.IsAdmin)
         {
             us.CoursePrivilege = user.CoursePrivilege;
         }
         us.Password = password;
         db.CP_User.Add(us);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Create([Bind(Include = "FromDate,ToDate,CourseId,Activate,MinCapacity,MaxCapacity,SerialFrom")] Duration duration)
 {
     if (ModelState.IsValid)
     {
         if (DateTime.Compare(duration.FromDate, duration.ToDate) > 0)
         {
             ViewBag.ModelErrors = "يجب ان يكون الفترة من اصغر من الفترة الى";
             return(View(duration));
         }
         if (duration.MinCapacity > duration.MaxCapacity)
         {
             ViewBag.ModelErrors = "يجب ان يكون الحد الادنى اصغر من الحد الاقصى";
             return(View(duration));
         }
         CP_Duration dur = new CP_Duration
         {
             CourseID     = duration.CourseId,
             FromDate     = duration.FromDate,
             ToDate       = duration.ToDate,
             Active       = duration.Activate,
             MinCapacity  = duration.MinCapacity,
             MaxCapacity  = duration.MaxCapacity,
             SerialFrom   = duration.SerialFrom,
             CreationDate = DateTime.Now,
             CreatorID    = Int32.Parse(Session["UserId"].ToString()),
             NumberRolled = 0
         };
         if (dur.Active == false)
         {
             dur.TerminatorID = Int32.Parse(Session["UserId"].ToString());
         }
         db.CP_Duration.Add(dur);
         db.SaveChanges();
         return(RedirectToAction("Index", new { id = duration.CourseId }));
     }
     return(View(duration));
 }