public ActionResult Activate(string code) { if (code != null) { try { var StudentCode = HashHelper.Decrypt(code); var registred = db.CP_Registration.Where(s => s.StudentCode == StudentCode).FirstOrDefault(); if (registred != null) { registred.ActivationStatus = true; db.Entry(registred).State = EntityState.Modified; db.SaveChanges(); ViewBag.Message = " تم تفعيل حسابك بنجاح لتسجيل الدخول <a href='/Account/Login'> اضغط هنا </a>"; return(View("Message")); } } catch (Exception) { ViewBag.Error = "حدث خطأء ما اثناء معالجة طلبك"; return(View("Error")); } } ViewBag.Error = "حدث خطأء ما اثناء معالجة طلبك"; return(View("Error")); }
public ActionResult Edit([Bind(Include = "DurationId,FromDate,ToDate,CourseId,Activate,MinCapacity,MaxCapacity,NumberRolled,SerialFrom,CreatorID,CreationDate")] Duration duration) { if (ModelState.IsValid) { CP_Duration dur = new CP_Duration { ID = duration.DurationId, FromDate = duration.FromDate, ToDate = duration.ToDate, Active = duration.Activate, MinCapacity = duration.MinCapacity, MaxCapacity = duration.MaxCapacity, SerialFrom = duration.SerialFrom, NumberRolled = duration.NumberRolled, CourseID = duration.CourseId, CreatorID = duration.CreatorId, ModificationDate = DateTime.Now, ModifiedID = Int32.Parse(Session["UserId"].ToString()), CreationDate = duration.CreationDate }; if (dur.Active == false) { dur.TerminatorID = Int32.Parse(Session["UserId"].ToString()); } db.Entry(dur).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = duration.CourseId })); } return(View(duration)); }
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)); }
public ActionResult Edit([Bind(Include = "CourseId,CourseImage,CourseName,GenderAllowed,CourseDetails,CreatorId,CreationDate")] 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); string fullPath = Request.MapPath("~/Uploads/" + course.CourseImage); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } 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 { ID = course.CourseId, Name = course.CourseName, Gender = course.GenderAllowed, Details = course.CourseDetails, Image = course.CourseImage, CreatorID = course.CreatorId, ModficationDate = DateTime.Now, ModifiedID = Int32.Parse(Session["UserId"].ToString()), CreationDate = course.CreationDate }; db.Entry(cours).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GenderAllowed = new SelectList(db.CP_Gender, "GenderId", "GenderName", course.GenderAllowed); return(View(course)); }
public ActionResult Edit([Bind(Include = "UserId,UserName,UserEmail,IsAdmin,CoursePrivilege,UserPassword,CreatorId,CreationDate")] User user) { if (ModelState.IsValid) { var ouser = db.CP_User.Find(user.UserId); if (ouser == null) { ViewBag.ModelErrors = "هذا المستخدم غير موجود"; ViewBag.CoursePrivilege = new SelectList(db.CP_Course, "ID", "Name", user.CoursePrivilege); return(View(user)); } var password = HashHelper.Encrypt(user.UserPassword); if (ouser.Password != user.UserPassword || ouser.Name != user.UserName) { var o2user = db.CP_User.Where(u => u.Name == user.UserName || u.Password == password).FirstOrDefault(); if (o2user != null && o2user.ID != ouser.ID) { if (o2user.Password == user.UserPassword) { ViewBag.ModelErrors = "كلمة المرور موجود مسبقا"; } else { ViewBag.ModelErrors = "اسم المستخدم موجود مسبقا"; } ViewBag.CoursePrivilege = new SelectList(db.CP_Course, "ID", "Name", user.CoursePrivilege); return(View(user)); } } ouser.Name = user.UserName; ouser.Email = user.UserEmail; if (!user.IsAdmin) { ouser.CoursePrivilege = user.CoursePrivilege; } else { ouser.CoursePrivilege = null; } ouser.Password = password; ouser.CreatorID = user.CreatorId; ouser.ModificationDate = DateTime.Now; ouser.ModifiedID = Int32.Parse(Session["UserId"].ToString()); ouser.CreationDate = user.CreationDate; db.Entry(ouser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }