public ActionResult CPPost(int?participantid, int?sessionid)
        {
            if (participantid != null)
            {
                var participant         = new ParticipiantRepository().Get(participantid.Value);
                evaluation_cp_post ecpp = new EvaluationCpPostRepository()
                                          .Get().FirstOrDefault(x => x.SessionId == sessionid && x.StudentId == participantid);
                if (ecpp == null)
                {
                    ecpp = new evaluation_cp_post();
                }
                ecpp.F1        = participant.Name + " " + participant.FatherName + " " + participant.Family;
                ecpp.StudentId = participantid.Value;
                ecpp.SessionId = sessionid.Value;
                if (participant.DateOfBirth != null)
                {
                    string date = participant.DateOfBirth.Value.ToString("ddMMyyyy");
                    ecpp.F2_1 = date.ToArray()[1] + "";
                    ecpp.F2_2 = date.ToArray()[0] + "";
                    ecpp.F2_3 = date.ToArray()[3] + "";
                    ecpp.F2_4 = date.ToArray()[2] + "";
                    ecpp.F2_5 = date.ToArray()[7] + "";
                    ecpp.F2_6 = date.ToArray()[6] + "";
                    ecpp.F2_7 = date.ToArray()[5] + "";
                    ecpp.F2_8 = date.ToArray()[4] + "";
                }
                ecpp.F3 = participant.Gender;

                return(View(ecpp));
            }
            return(View());
        }
        public ActionResult ParticipantProfile(participant_profile participant, HttpPostedFileBase file)
        {
            var participantRepo = new ParticipiantRepository();
            var oparticipant    = participantRepo.Get(participant.Id);

            oparticipant.Mobile            = participant.Mobile;
            oparticipant.Gender            = participant.Gender;
            oparticipant.DateOfBirth       = participant.DateOfBirth;
            oparticipant.ProgrammName1     = participant.ProgrammName1;
            oparticipant.FatherMobile      = participant.Mobile;
            oparticipant.City              = participant.City;
            oparticipant.SchoolId          = participant.SchoolId;
            oparticipant.FacebookAddress   = participant.FacebookAddress;
            oparticipant.TwitterAddress    = participant.TwitterAddress;
            oparticipant.SnapChatAddress   = participant.SnapChatAddress;
            oparticipant.Stage             = participant.Stage;
            oparticipant.user.FirstLogin   = true;
            oparticipant.IsProfileComplete = true;
            oparticipant.Instagram         = participant.Instagram;
            oparticipant.Class             = participant.Class;
            if (file != null)
            {
                string fileName = "~/Uploads/ImageLibrary/" + Guid.NewGuid() + Path.GetExtension(file.FileName);
                string filePath = Server.MapPath(fileName);
                file.SaveAs(filePath);
                oparticipant.PhotoPath = fileName;
            }
            participantRepo.Put(participant.Id, oparticipant);
            return(RedirectToAction("Index", "Session"));
        }
 public ActionResult SYCPreP2(int?participantid, int?sessionid)
 {
     if (participantid != null)
     {
         var participant = new ParticipiantRepository().Get(participantid.Value);
         evaluation_syc_pre_part2 ecpp = new EvaluationSycPrePart2Repository()
                                         .Get().FirstOrDefault(x => x.SessionId == sessionid && x.StudentId == participantid);
         if (ecpp == null)
         {
             ecpp = new evaluation_syc_pre_part2();
         }
         ecpp.StudentId = participantid.Value;
         ecpp.SessionId = sessionid.Value;
         ecpp.F1        = participant.school.SchoolName;
         ecpp.F5        = participant.Name;
         ecpp.F6        = participant.FatherName;
         ecpp.F7        = participant.Family;
         ecpp.F8        = participant.Mobile;
         ecpp.F9        = participant.Email;
         ecpp.F10       = participant.FacebookAddress;
         ecpp.F11       = participant.TwitterAddress;
         return(View(ecpp));
     }
     return(View());
 }
 public ActionResult PFPost(int?participantid, int?sessionid)
 {
     if (participantid != null)
     {
         var oSession            = new SessionRepository().Get(sessionid.Value);
         var participant         = new ParticipiantRepository().Get(participantid.Value);
         evaluation_pf_post ecpp = new EvaluationPFPostRepository()
                                   .Get().FirstOrDefault(x => x.SessionId == sessionid && x.StudentId == participantid);
         if (ecpp == null)
         {
             ecpp = new evaluation_pf_post();
         }
         ecpp.StudentId = participantid.Value;
         ecpp.SessionId = sessionid.Value;
         ecpp.F1        = participant.Name + " " + participant.FatherName + " " + participant.Family;
         ecpp.F2        = participant.Email;
         ecpp.F4        = participant.Gender;
         if (participant.DateOfBirth != null)
         {
             string date = participant.DateOfBirth.Value.ToString("ddMMyyyy");
             ecpp.F5_1 = date.ToArray()[1] + "";
             ecpp.F5_2 = date.ToArray()[0] + "";
             ecpp.F5_3 = date.ToArray()[3] + "";
             ecpp.F5_4 = date.ToArray()[2] + "";
             ecpp.F5_5 = date.ToArray()[7] + "";
             ecpp.F5_6 = date.ToArray()[6] + "";
             ecpp.F5_7 = date.ToArray()[5] + "";
             ecpp.F5_8 = date.ToArray()[4] + "";
         }
         ecpp.F6 = participant.school.SchoolName;
         ecpp.F7 = oSession.volunteer_profile.VolunteerName;
         return(View(ecpp));
     }
     return(View());
 }
示例#5
0
        public ActionResult RequestSession(List <session> sessions)
        {
            if (sessions != null && sessions.Count > 0)
            {
                var cu                 = Session["user"] as ContextUser;
                int participantId      = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
                var repository         = new SessionRepository();
                var oSession           = repository.Get();
                var oSessionSelected   = oSession.Where(y => sessions.Where(x => x.IsSelected).Select(x => x.Id).ToList().Contains(y.Id)).ToList();
                var oSessionUnSelected = oSession.Where(y => sessions.Where(x => !x.IsSelected).Select(x => x.Id).ToList().Contains(y.Id)).ToList();

                foreach (var item in oSessionSelected)
                {
                    var sp = item.session_participant.Where(x => x.ParticipantID == participantId).FirstOrDefault();
                    if (sp == null)
                    {
                        item.session_participant.Add(new session_participant {
                            SessionID = item.Id, ParticipantID = participantId
                        });
                    }
                }
                repository.RemoveSessionParticipants(oSessionUnSelected, participantId);

                repository.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
示例#6
0
        // GET: Funder
        public ActionResult Index(string sortOrder, string filter, string archived, int page = 1, Guid?archive = null)
        {
            ViewBag.searchQuery  = string.IsNullOrEmpty(filter) ? "" : filter.Trim();
            ViewBag.showArchived = (archived ?? "") == "on";

            page = page > 0 ? page : 1;
            int pageSize = 0;

            pageSize = pageSize > 0 ? pageSize : 10;

            ViewBag.CurrentSort = sortOrder;

            IEnumerable <session> session;
            var repository = new SessionRepository();

            repository.SetOccuredStatus();


            if (archive != null)
            {
                var oSession = repository.GetByRowId(archive.Value);
                oSession.IsActive = !oSession.IsActive;
                repository.Put(oSession.Id, oSession);
            }

            var cu = Session["user"] as ContextUser;

            int corSchoolId = 0;

            if (cu.EnumRole != EnumUserRole.Volunteer)
            {
                corSchoolId = new CoordinatorRepository().GetSchoolIdByUserId(cu.OUser.Id);
            }
            var participantId = 0;

            if (cu.EnumRole == EnumUserRole.Participant)
            {
                participantId = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
            }
            session = repository.Get().Where(x =>
            {
                return((filter == null || x.ProgramName.ToLower().Contains(filter.ToLower()) ||
                        (x.school != null && (x.school.SchoolName.ToLower().Contains(filter.ToLower()) ||
                                              x.school.City.ToLower().Contains(filter.ToLower())))
                        ) &&
                       ((cu.EnumRole == EnumUserRole.SuperAdmin ||
                         (cu.EnumRole == EnumUserRole.Participant && x.session_participant
                          .Select(y => y.ParticipantID)
                          .Contains(participantId)) ||
                         (cu.EnumRole == EnumUserRole.Volunteer &&
                          ((x.VolunteerId == null && x.Status == "Approved") ||
                           (x.VolunteerId.HasValue && x.VolunteerId.Value == cu.OUser.Id && (x.Status == "Approved" || x.Status == "Occured")))) ||
                         (cu.EnumRole == EnumUserRole.Coordinator && x.SchoolID == corSchoolId))));
            });
            //Sorting order
            session       = session.OrderByDescending(x => x.CreatedAt);
            ViewBag.Count = session.Count();

            return(View(session.ToPagedList(page, pageSize)));
        }
示例#7
0
        public ActionResult RequestSession()
        {
            var cu            = Session["user"] as ContextUser;
            int participantId = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
            var repository    = new SessionRepository();
            var oSession      = repository.Get().Where(x => x.Status == "Approved").ToList();

            foreach (var item in oSession)
            {
                if (item.session_participant.Any(x => x.ParticipantID == participantId))
                {
                    item.IsSelected = true;
                }
            }
            return(View(oSession));
        }
        // GET: Funder
        public ActionResult Index(string sortOrder, string filter, string archived, int page = 1, Guid?archive = null)
        {
            //PdfGenerator.PdfGenerator pdf = new PdfGenerator.PdfGenerator();
            //pdf.GenerateOnflyPdf();

            //ExcelReader.Read(@"C:\Users\malikwaqar\Desktop\bredford code analysic.xlsx");

            ViewBag.searchQuery  = string.IsNullOrEmpty(filter) ? "" : filter;
            ViewBag.showArchived = (archived ?? "") == "on";

            page = page > 0 ? page : 1;
            int pageSize = 0;

            pageSize = pageSize > 0 ? pageSize : 10;

            ViewBag.CurrentSort = sortOrder;

            IEnumerable <participant_profile> participiant;
            var repository = new ParticipiantRepository();

            if (archive != null)
            {
                var oParticipiant = repository.GetByRowId(archive.Value);
                oParticipiant.isActive      = !oParticipiant.isActive;
                oParticipiant.user.IsLocked = !oParticipiant.isActive;

                repository.Put(oParticipiant.Id, oParticipiant);
            }
            if (string.IsNullOrEmpty(filter))
            {
                participiant = repository.GetAll();
            }
            else
            {
                participiant = repository.GetAll().Where(x => x.Name.ToLower
                                                             ().Contains(filter.ToLower()) || x.NationalID.Contains(filter));
            }
            //Sorting order
            participiant  = participiant.OrderByDescending(x => x.CreatedAt);
            ViewBag.Count = participiant.Count();

            return(View(participiant.ToPagedList(page, pageSize)));
        }
        public ActionResult Edit(Guid?id, int sessionId = 0)
        {
            participant_profile participaintModel = null;

            if (id == null)
            {
                participaintModel          = new participant_profile();
                participaintModel.isActive = true;
                participaintModel.Password = Membership.GeneratePassword(8, 4);
            }
            else
            {
                var participiantRepo = new ParticipiantRepository();
                participaintModel          = participiantRepo.GetByRowId(id.Value);
                participaintModel.Password = EncryptionKeys.Decrypt(participaintModel.user.Password);
            }
            if (sessionId > 0)
            {
                participaintModel.SessionId = sessionId;
                return(PartialView("_ManageParticipant", participaintModel));
            }
            return(View(participaintModel));
        }
示例#10
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (Request["button"] != null)
            {
                return(RedirectToAction("VolunteerProfile", "volunteer"));
            }

            var a          = 0;
            var repository = new AccountRepository();
            var user       = repository.Get().FirstOrDefault(x => x.Username == model.Username.Trim() && !x.IsLocked);

            if (user == null)
            {
                var participantRepo = new ParticipiantRepository();
                var participant     = participantRepo.Get().FirstOrDefault(x => x.NationalID == model.Username && x.isActive);
                if (participant != null)
                {
                    user = participant.user;
                }
            }
            if (user != null)
            {
                var password1 = EncryptionKeys.Decrypt(user.Password);
                var password  = EncryptionKeys.Encrypt(model.Password);
                if (user.Password.Equals(password))
                {
                    var    role     = new RoleRepository().Get(user.RoleId);
                    var    enumRole = (EnumUserRole)role.Code;
                    string route    = Request.Form["route"];
                    if (route == "manager" && enumRole != EnumUserRole.SuperAdmin)
                    {
                        return(RedirectToAction("Admin", new { error = true }));
                    }
                    if (route != "manager" && enumRole == EnumUserRole.SuperAdmin)
                    {
                        return(RedirectToAction("Login", new { error = true }));
                    }
                    if (enumRole == EnumUserRole.Coordinator)
                    {
                    }
                    var cu = new ContextUser
                    {
                        OUser     = user,
                        EnumRole  = enumRole,
                        Role      = role,
                        PhotoPath = "/img/avatars/admin.png"
                    };

                    Session["user"] = cu;
                    FormsAuthentication.SetAuthCookie(user.Username, false);
                    //var claims = new List<Claim>();
                    //claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Username));
                    //claims.Add(new Claim(ClaimTypes.Name, user.FirstName));
                    //claims.Add(new Claim(ClaimTypes.Email, user.Email));
                    //claims.Add(new Claim(ClaimTypes.Role, userRole.ToString("g")));
                    //claims.Add(new Claim(ClaimTypes.Sid, user.Id.ToString()));

                    //var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

                    //var ctx = Request.GetOwinContext();
                    //var authenticationManager = ctx.Authentication;
                    //authenticationManager.SignIn(id);


                    return(RedirectToPortal(enumRole, user));
                }
            }

            string route1 = Request.Form["route"];

            if (route1 == "manager")
            {
                return(RedirectToAction("Admin", new { error = true }));
            }
            if (route1 != "manager")
            {
                return(RedirectToAction("Login", new { error = true }));
            }

            return(View(model));

            //// This doesn't count login failures towards account lockout
            //// To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        return RedirectToLocal(returnUrl);
            //    case SignInStatus.LockedOut:
            //        return View("Lockout");
            //    case SignInStatus.RequiresVerification:
            //        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            //    case SignInStatus.Failure:
            //    default:
            //        ModelState.AddModelError("", "Invalid login attempt.");
            //        return View(model);
            //}
        }
示例#11
0
        private ActionResult RedirectToPortal(EnumUserRole userRole, user user)
        {
            switch (userRole)
            {
            case EnumUserRole.SuperAdmin:
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("DashBoard", "Home"));

            case EnumUserRole.Coordinator:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                var oCordinator = new CoordinatorRepository().GetByUserId(user.Id);
                if (oCordinator.IsProfileComplete == null || !oCordinator.IsProfileComplete.Value)
                {
                    return(RedirectToAction("CoordinatorProfile", "Coordinator"));
                }
                var cu = Session["user"] as ContextUser;
                if (cu != null)
                {
                    cu.PhotoPath    = oCordinator.PhotoPath;
                    Session["user"] = cu;
                }
                return(RedirectToAction("Index", "Session"));
            }

            case EnumUserRole.Volunteer:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(AfterExternalLoginCallBack(user.FirstName + user.LastName, user.Email, user.Id.ToString(), "user", "", user.FirstName + " " + user.LastName));
            }

            case EnumUserRole.Participant:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                var participant = new ParticipiantRepository().GetByUserId(user.Id);

                if (participant.IsProfileComplete == null || !participant.IsProfileComplete.Value)
                {
                    return(RedirectToAction("ParticipantProfile", "Participant"));
                }
                var cu = Session["user"] as ContextUser;
                if (cu != null)
                {
                    cu.PhotoPath    = participant.PhotoPath;
                    Session["user"] = cu;
                }
                return(RedirectToAction("Index", "Session"));
            }

            case EnumUserRole.Approver1:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Approver2:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Approver3:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Funder:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Report"));
            }

            default:
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult UploadExcel(ExcelModel model, HttpPostedFileBase file)
        {
            var rowuid = new SessionRepository().Get(model.SessionId).RowGUID;

            try
            {
                string fileName = "~/Uploads/" + file.FileName;
                string filePath = Server.MapPath(fileName);
                file.SaveAs(filePath);
                var participantRepo             = new ParticipiantRepository();
                participant_profile participant = null;
                var cu = Session["user"] as ContextUser;
                List <participant_profile> profileList = new List <participant_profile>();
                using (ExcelPackage xlPackage = new ExcelPackage(new FileInfo(filePath)))
                {
                    var sheet  = xlPackage.Workbook.Worksheets[1];
                    var rowCnt = sheet.Dimension.End.Row;
                    for (int row = 2; row <= rowCnt; row++)
                    {
                        participant_profile profile = new participant_profile();
                        profile.Name = GetValue(sheet, row, 1);
                        if (string.IsNullOrEmpty(profile.Name))
                        {
                            continue;
                        }
                        profile.FatherName = GetValue(sheet, row, 2);
                        profile.Family     = GetValue(sheet, row, 3);
                        profile.NationalID = GetValue(sheet, row, 4);
                        profile.Mobile     = GetValue(sheet, row, 5);
                        profile.Email      = GetValue(sheet, row, 6);
                        profileList.Add(profile);
                    }

                    string error = ValidateParticipantRecords(profileList);
                    if (error != null)
                    {
                        return(RedirectToAction("Edit", "Session", new { id = rowuid, excelerror = true, error = error }));
                    }
                }
                foreach (var profile in profileList)
                {
                    participant = participantRepo.GetParticipant(profile.NationalID);

                    if (participant == null)
                    {
                        participant = new participant_profile
                        {
                            RowGuid   = Guid.NewGuid(),
                            CreatedAt = DateTime.Now,
                            CreatedBy = cu.OUser.Id,
                            Email     = profile.Email
                        };
                    }
                    var isSessionAttached = participant.session_participant.Where(x => x.SessionID == model.SessionId).Any();
                    if (model.SessionId > 0 && !isSessionAttached)
                    {
                        participant.session_participant.Add(
                            new session_participant {
                            SessionID = model.SessionId, ParticipantID = participant.Id
                        });
                    }

                    var userRole = new RoleRepository().Get().Where(x => x.Code == (int)EnumUserRole.Participant)
                                   .FirstOrDefault();
                    if (participant.ParticipantUserID == 0)
                    {
                        participant.user = new user
                        {
                            RowGuid          = Guid.NewGuid(),
                            Email            = profile.Email,
                            Username         = profile.Email,
                            RegistrationDate = DateTime.Now,
                            FirstName        = profile.Name,
                            RoleId           = userRole.Id,
                            CreatedAt        = DateTime.Now,
                            ValidFrom        = DateTime.Now,
                            FirstLogin       = false,
                            IsMobileVerified = false,
                            IsEmailVerified  = false,
                            CreatedBy        = cu.OUser.Id,
                            Password         = EncryptionKeys.Encrypt(Membership.GeneratePassword(8, 4))
                        }
                    }
                    ;
                    participant.Name       = profile.Name;
                    participant.FatherName = profile.FatherName;
                    participant.Family     = profile.Family;
                    participant.NationalID = profile.NationalID;
                    participant.Mobile     = profile.Mobile;
                    participant.isActive   = true;
                    if (participant.Id == 0)
                    {
                        string url = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
                                     "/Account/Login";
                        var bogusController       = Util.CreateController <EmailTemplateController>();
                        EmailTemplateModel emodel =
                            new EmailTemplateModel
                        {
                            Title       = "Complete Profile",
                            RedirectUrl = url,
                            UserName    = participant.Email,
                            User        = participant.Email,
                            Password    = EncryptionKeys.Decrypt(participant.user.Password)
                        };
                        string body =
                            Util.RenderViewToString(bogusController.ControllerContext, "CoordinatorProfile", emodel);
                        EmailSender.SendSupportEmail(body, participant.Email);
                        participant.IsEmailSent = true;
                        participantRepo.Post(participant);
                    }
                    else
                    {
                        participantRepo.Put(participant.Id, participant);
                    }
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Edit", "Session", new { id = rowuid, excelerror = true, error = Participant.UploadError }));

                throw ex;
            }
            return(RedirectToAction("Index", "Session"));
        }
        public ActionResult ParticipantProfile()
        {
            ViewBag.gender = new List <SelectListItem>
            {
                new SelectListItem {
                    Selected = true, Text = General.Male, Value = "Male"
                },
                new SelectListItem {
                    Selected = false, Text = General.Female, Value = "Female"
                }
            };
            var cities = new CityRepository().Get().Distinct().Select(x =>
                                                                      new SelectListItem {
                Text = x.City + " (" + x.City_ar + ")", Value = x.City + "", Selected = x.City == "Jeddah"
            }).ToList();

            ViewBag.citiesdd        = cities;
            ViewBag.stageofschooldd = new List <SelectListItem>
            {
                new SelectListItem {
                    Selected = true, Text = General.Primary, Value = "Primary "
                },
                new SelectListItem {
                    Selected = false, Text = General.Middle, Value = "Middle"
                },
                new SelectListItem {
                    Selected = false, Text = General.Secondary, Value = "Secondary"
                }
            };
            var school = new SchoolRepository().Get().Select(x =>
                                                             new SelectListItem {
                Text = x.SchoolName, Value = x.Id + ""
            }).ToList();

            ViewBag.school = school;

            var cu            = Session["user"] as ContextUser;
            var repository    = new ParticipiantRepository();
            var oParticipiant = repository.GetByUserId(cu.OUser.Id);

            if (oParticipiant.session_participant != null && oParticipiant.session_participant.Count > 0)
            {
                var sessions = oParticipiant.session_participant.Select(x => x.session).Select(x =>
                                                                                               new SelectListItem {
                    Text = x.ProgramName, Value = x.ProgramName
                }).ToList();

                ViewBag.sessions = sessions;
            }
            else
            {
                var sessions = new SessionRepository().Get().Select(x =>
                                                                    new SelectListItem {
                    Text = x.ProgramName, Value = x.ProgramName
                }).ToList();

                ViewBag.sessions = sessions;
            }

            return(View(oParticipiant));
        }
        public ActionResult Edit(participant_profile profile)
        {
            var accountRepo                 = new AccountRepository();
            var participantRepo             = new ParticipiantRepository();
            participant_profile participant = null;
            var cu = Session["user"] as ContextUser;

            if (profile.Id == 0)
            {
                if (accountRepo.EmailExist(profile.Email))
                {
                    ViewBag.EmailExist = true;
                    return(View(profile));
                }
                participant = participantRepo.GetParticipant(profile.NationalID);
                if (participant == null)
                {
                    participant = new participant_profile
                    {
                        RowGuid   = Guid.NewGuid(),
                        CreatedAt = DateTime.Now,
                        CreatedBy = cu.OUser.Id,
                        Email     = profile.Email,
                    };
                }
                if (profile.SessionId > 0)
                {
                    participant.session_participant.Add(new session_participant {
                        SessionID = profile.SessionId, ParticipantID = participant.Id
                    });
                }
            }
            else
            {
                participant           = participantRepo.Get(profile.Id);
                participant.UpdatedAt = DateTime.Now;
                participant.UpdatedBy = cu.OUser.Id;
            }

            var userRole = new RoleRepository().Get().Where(x => x.Code == (int)EnumUserRole.Participant).FirstOrDefault();

            if (participant.ParticipantUserID == 0)
            {
                participant.user = new user
                {
                    RowGuid          = Guid.NewGuid(),
                    Email            = profile.Email,
                    Username         = profile.Email,
                    RegistrationDate = DateTime.Now,
                    FirstName        = profile.Name,
                    RoleId           = userRole.Id,
                    CreatedAt        = DateTime.Now,
                    ValidFrom        = DateTime.Now,
                    FirstLogin       = false,
                    IsMobileVerified = false,
                    IsEmailVerified  = false,
                    CreatedBy        = cu.OUser.Id,
                    Password         = EncryptionKeys.Encrypt(profile.Password)
                }
            }
            ;
            participant.Name       = profile.Name;
            participant.FatherName = profile.FatherName;
            participant.Family     = profile.Family;
            participant.NationalID = profile.NationalID;
            if (profile.MobileNo != null)
            {
                participant.Mobile = profile.MobileNo;
            }
            else
            {
                participant.Mobile = profile.Mobile;
            }
            participant.isActive      = profile.isActive;
            participant.user.IsLocked = !participant.isActive;
            if (participant.Id == 0)
            {
                string             url             = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Login";
                var                bogusController = Util.CreateController <EmailTemplateController>();
                EmailTemplateModel model           = new EmailTemplateModel {
                    Title = "Complete Profile", RedirectUrl = url, UserName = participant.Email, Password = EncryptionKeys.Decrypt(participant.user.Password), ParticipantName = participant.Name, User = participant.user.FirstName
                };
                string body = Util.RenderViewToString(bogusController.ControllerContext, "ParticipantProfile", model);
                EmailSender.SendSupportEmail(body, participant.Email);
                participant.IsEmailSent = true;
                participantRepo.Post(participant);
            }
            else
            {
                participantRepo.Put(participant.Id, participant);
            }
            if (Request["participant"] == "true")
            {
                var rowId = new SessionRepository().Get(profile.SessionId).RowGUID;
                return(RedirectToAction("Edit", "Session", new { id = rowId }));
            }
            return(RedirectToAction("Index"));
        }
示例#15
0
        public ActionResult Edit(Guid?id, int page = 1)
        {
            SelectListItem defaultselect = new SelectListItem {
                Text = General.Select, Value = "0"
            };

            var school = new SchoolRepository().Get().Select(x =>
                                                             new SelectListItem {
                Text = x.SchoolName, Value = x.Id + ""
            }).ToList();

            school.Insert(0, defaultselect);
            ViewBag.school = school;

            var volunteer = new VolunteerRepository().GetApprovedVolunteer().Select(x =>
                                                                                    new SelectListItem {
                Text = x.VolunteerName, Value = x.Id + ""
            }).ToList();

            volunteer.Insert(0, defaultselect);
            ViewBag.volunteer = volunteer;

            var certificatesVolunteer = new CertificateRepository().Get().Where(x => x.TypeCertificate == "Volunteer").Select(x =>
                                                                                                                              new SelectListItem {
                Text = x.Name, Value = x.Id + ""
            }).ToList();

            certificatesVolunteer.Insert(0, defaultselect);
            ViewBag.certificatesVolunteer = certificatesVolunteer;

            var certificatesStudent = new CertificateRepository().Get().Where(x => x.TypeCertificate == "Student").Select(x =>
                                                                                                                          new SelectListItem {
                Text = x.Name, Value = x.Id + ""
            }).ToList();

            certificatesStudent.Insert(0, defaultselect);
            ViewBag.certificatesStudent = certificatesStudent;

            var evaluationCatagory = new EvaluationFormRepository().Get().GroupBy(x => x.Catagory).Select(x => x.First()).Select(x =>
                                                                                                                                 new SelectListItem {
                Text = x.Catagory, Value = x.Catagory + ""
            }).ToList();

            evaluationCatagory.Insert(0, defaultselect);
            ViewBag.evaluationCatagory = evaluationCatagory;

            var cu = Session["user"] as ContextUser;

            session sessionModel;

            if (id == null)
            {
                sessionModel                    = new session();
                sessionModel.IsActive           = true;
                sessionModel.PropesedDateString = DateTime.Now.AddMonths(1).ToString("dd/MM/yyyy");
            }
            else
            {
                var sessionRepo = new SessionRepository();
                sessionModel = sessionRepo.GetByRowId(id.Value);
                sessionModel.PropesedDateString = sessionModel.ProposedDateTime.ToString("dd/MM/yyyy");
                sessionModel.EnumSessionStatus  = (SessionStatus)Enum.Parse(typeof(SessionStatus), sessionModel.Status);
                if (sessionModel.ActualDateTime != null)
                {
                    sessionModel.ActualDateString = sessionModel.ActualDateTime.Value.ToString("dd/MM/yyyy");
                    if ((sessionModel.ActualDateTime.Value.Date - DateTime.Now.Date).Hours >= 72 && sessionModel.EnumSessionStatus == SessionStatus.Approved && cu.EnumRole == EnumUserRole.Coordinator)
                    {
                        sessionModel.ChangeDateVisible = true;
                    }
                }
                if (cu.EnumRole == EnumUserRole.Participant)
                {
                    string eve_cat = sessionModel.StudentEvaluationCatagory;
                    if (!string.IsNullOrEmpty(eve_cat))
                    {
                        int participantId = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
                        var sParticipant  = sessionModel.session_participant.Where(x => x.ParticipantID == participantId).First();
                        sessionModel.EvaluationFormFilled  = (sParticipant.IsPreEvaluated ?? false) && (sParticipant.IsPostEvaluated ?? false);
                        sessionModel.IsPreFilledByStudent  = (sParticipant.IsPreEvaluated ?? false);
                        sessionModel.IsPostFilledByStudent = (sParticipant.IsPostEvaluated ?? false);
                        sessionModel.IsAttendenseMarked    = sParticipant.VolunteerMarkedAttendence;
                    }
                }
                if (cu.EnumRole == EnumUserRole.Coordinator)
                {
                    sessionModel.IsFilledCoordinator = new EvaluationVolunteerRepository().GetEvaluationForm(sessionModel.Id) != null;
                }
                if (cu.EnumRole == EnumUserRole.Volunteer)
                {
                    sessionModel.IsFilledVolunteer = new EvaluationCoordinatorRepository().GetEvaluationForm(sessionModel.Id) != null;
                }
                var session_evaluationform_photo = sessionModel.session_evaluationform_photo.Select(x => x.FilePath).ToArray();
                sessionModel.EvaluationImageLink = string.Join(",", session_evaluationform_photo) + ",";
                var session_photo = sessionModel.session_photo.Select(x => x.FilePath).ToArray();
                sessionModel.SessionImageLink = string.Join(",", session_photo) + ",";

                sessionModel.PagedParticipants = sessionModel.session_participant.Select(x => x.participant_profile).OrderByDescending(x => x.CreatedAt).ToPagedList(page, 5);
                ViewBag.Count = sessionModel.session_participant.Count();
                ViewBag.IsSessionEnabledForVolunteer = true;
            }
            return(View(sessionModel));
        }
示例#16
0
        public ActionResult Edit(session session)
        {
            var      sessionRepo   = new SessionRepository();
            session  oSession      = null;
            var      cu            = Session["user"] as ContextUser;
            DateTime?oldActualDate = null;

            if (session.Id == 0)
            {
                oSession           = new session();
                oSession.RowGUID   = Guid.NewGuid();
                oSession.CreatedAt = DateTime.Now;
                oSession.CreatedBy = cu.OUser.Id;
                oSession.Status    = SessionStatus.Pending.ToString();
            }
            else
            {
                oSession           = sessionRepo.Get(session.Id);
                oSession.UpdatedAt = DateTime.Now;
                oldActualDate      = oSession.ActualDateTime;
                // oSession.UpdatedBy = int.Parse(sid);
            }
            var currentStatus = (SessionStatus)Enum.Parse(typeof(SessionStatus), oSession.Status);


            if (cu.EnumRole == EnumUserRole.SuperAdmin && currentStatus == SessionStatus.Pending)
            {
                oSession.ProgramPurpose = "ProgramPurposeNotUsed";
                oSession.TargetGroup    = session.TargetGroup;

                if (oSession.SchoolID == null && session.SchoolID != null && session.SchoolID.Value != 0)
                {
                    var cor                   = new CoordinatorRepository().GetBySchool(session.SchoolID.Value);
                    var user                  = new AccountRepository().Get(oSession.CreatedBy);
                    var bogusController       = Util.CreateController <EmailTemplateController>();
                    EmailTemplateModel emodel =
                        new EmailTemplateModel
                    {
                        Title           = "Notification: Session Created For School",
                        User            = user.FirstName,
                        CoordinatorName = cor.CoordinatorName,
                        SessionTitle    = oSession.ProgramName,
                        UserName        = user.Username,
                        Email           = cor.CoordinatorEmail
                    };
                    string body =
                        Util.RenderViewToString(bogusController.ControllerContext, "SessionCreatedSchool", emodel);
                    EmailSender.SendSupportEmail(body, cor.CoordinatorEmail);
                }
                oSession.SchoolID                  = session.SchoolID == 0 ? null : session.SchoolID;
                oSession.ProgramName               = session.ProgramName;
                oSession.ProposedDateTime          = DateTime.ParseExact(session.PropesedDateString, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                oSession.ProposedEndDateTime       = session.ProposedEndDateTime;
                oSession.VolunteerId               = session.VolunteerId == 0 ? null : session.VolunteerId;
                oSession.StudentCertificate        = session.StudentCertificate == 0 ? null : session.StudentCertificate;
                oSession.VolunteerCertificate      = session.VolunteerCertificate == 0 ? null : session.VolunteerCertificate;
                oSession.StudentEvaluationCatagory = session.StudentEvaluationCatagory;
            }
            if (session.ActualDateString != null)
            {
                oSession.ActualDateTime = DateTime.ParseExact(session.ActualDateString, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            if (currentStatus == SessionStatus.DateChanges)
            {
                if (session.SendKitByMailCourier && !oSession.SendKitByMailCourier)
                {
                    var cor                   = oSession.school.coordinator_profile.First();
                    var user                  = new AccountRepository().Get(oSession.CreatedBy);
                    var bogusController       = Util.CreateController <EmailTemplateController>();
                    EmailTemplateModel emodel =
                        new EmailTemplateModel
                    {
                        Title           = "Injaz: Administrator send kit by mail courier.",
                        User            = user.FirstName,
                        CoordinatorName = cor.CoordinatorName,
                        SessionTitle    = oSession.ProgramName,
                    };
                    string body =
                        Util.RenderViewToString(bogusController.ControllerContext, "SendKitBymailCourier", emodel);
                    EmailSender.SendSupportEmail(body, cor.CoordinatorEmail);
                }
                oSession.SendKitByMailCourier = session.SendKitByMailCourier;
            }
            if (cu.EnumRole == EnumUserRole.Coordinator && (currentStatus == SessionStatus.Approved || currentStatus == SessionStatus.Rejected))
            {
                if (session.ConfirmKitReceivedBySchool && !oSession.ConfirmKitReceivedBySchool)
                {
                    var cor                   = oSession.school.coordinator_profile.First();
                    var user                  = new AccountRepository().Get(oSession.CreatedBy);
                    var bogusController       = Util.CreateController <EmailTemplateController>();
                    EmailTemplateModel emodel =
                        new EmailTemplateModel
                    {
                        Title           = "Injaz: Confirm Kit Received By School.",
                        CoordinatorName = cor.CoordinatorName,
                        SessionTitle    = oSession.ProgramName,
                        User            = cor.user.FirstName
                    };
                    string body =
                        Util.RenderViewToString(bogusController.ControllerContext, "ConfirmKitReceivedBySchool", emodel);
                    EmailSender.SendSupportEmail(body, user.Email);
                }
                oSession.ConfirmKitReceivedBySchool = session.ConfirmKitReceivedBySchool;
            }
            if (currentStatus == SessionStatus.Pending && oSession.ActualDateTime != null)
            {
                if (oSession.ProposedDateTime.Date == oSession.ActualDateTime.Value.Date)
                {
                    if (oSession.Status != SessionStatus.Approved.ToString())
                    {
                        SendEmailNotificationsApprovedByAdmin(oSession);
                    }
                    oSession.Status          = SessionStatus.Approved.ToString();
                    oSession.ApprovedByAdmin = true;
                }
                else
                {
                    if (oSession.Status != SessionStatus.DateChanges.ToString())
                    {
                        SendEmailNotificationDateChanged(oSession);
                    }
                    oSession.Status = SessionStatus.DateChanges.ToString();
                }
            }
            if (currentStatus == SessionStatus.Approved && oldActualDate != null && oSession.ActualDateTime != oldActualDate)
            {
                if (oSession.Status != SessionStatus.Approved.ToString())
                {
                    SendEmailNotificationDateChanged(oSession);
                }
                oSession.Status          = SessionStatus.DateChanges.ToString();
                oSession.ApprovedByAdmin = false;
            }
            if (session.SubmitButton != null)
            {
                if (session.SubmitButton == "approved")
                {
                    if (oSession.Status != SessionStatus.Approved.ToString())
                    {
                        SendEmailNotificationsApprovedByAdmin(oSession);
                    }
                    oSession.Status          = SessionStatus.Approved.ToString();
                    oSession.ApprovedByAdmin = true;
                }
                if (session.SubmitButton == "submitpre")
                {
                    int    participantId = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
                    string eve_cat       = oSession.StudentEvaluationCatagory;
                    string form          = new EvaluationFormRepository().Get().First(x => x.Catagory == eve_cat && x.SubCatagory == "pre").FormPath;
                    return(RedirectToAction(form, "EvaluationForm", new { participantid = participantId, sessionid = oSession.Id }));
                }
                if (session.SubmitButton == "submitpost")
                {
                    int    participantId = new ParticipiantRepository().GetByUserId(cu.OUser.Id).Id;
                    string eve_cat       = oSession.StudentEvaluationCatagory;
                    string form          = new EvaluationFormRepository().Get().First(x => x.Catagory == eve_cat && x.SubCatagory == "post").FormPath;
                    return(RedirectToAction(form, "EvaluationForm", new { participantid = participantId, sessionid = oSession.Id }));
                }
                if (session.SubmitButton == "request")
                {
                    //oSession.MarkedCompletedByVolunteer = true;
                    var volunteer = new VolunteerRepository().GetByGoogleId(cu.GoogleId) ?? new VolunteerRepository().GetByLinkedInId(cu.GoogleId);
                    oSession.VolunteerId = volunteer.Id;

                    var user                  = new AccountRepository().Get(oSession.CreatedBy);
                    var bogusController       = Util.CreateController <EmailTemplateController>();
                    EmailTemplateModel emodel =
                        new EmailTemplateModel
                    {
                        Title         = "Injaz:Volunteer Assign Session",
                        VolunteerName = volunteer.VolunteerName,
                        SessionTitle  = oSession.ProgramName,
                        User          = user.FirstName
                    };
                    string body =
                        Util.RenderViewToString(bogusController.ControllerContext, "VolunteerAssignSession", emodel);
                    EmailSender.SendSupportEmail(body, user.Email);
                }
                if (session.SubmitButton == "confirm")
                {
                    return(RedirectToAction("StudentAttendense", new { sessionId = oSession.RowGUID }));
                }
                if (session.SubmitButton == "reject")
                {
                    oSession.Status = SessionStatus.Rejected.ToString();
                }
                if (session.SubmitButton == "feedback")
                {
                    var participant = new ParticipiantRepository().GetByUserId(cu.OUser.Id);

                    return(RedirectToAction("FeedBack", new { sessionId = oSession.Id, participantId = participant.Id }));
                }
                if (session.SubmitButton == "coordinatorform")
                {
                    int corId = new CoordinatorRepository().GetByUserId(oSession.school.CoordinatorUserId).Id;
                    return(RedirectToAction("CoordinatorForm", "EvaluationForm", new { sessionId = oSession.Id, volId = oSession.volunteer_profile.Id, corId = corId }));
                }
                if (session.SubmitButton == "viewcertificate" || session.SubmitButton == "volunteerviewcertificate")
                {
                    var    participant     = new ParticipiantRepository().GetByUserId(cu.OUser.Id);
                    string certificatePath = null;

                    List <PdfCoordinatesModel> pdfCoordinates = null;
                    if (cu.EnumRole == EnumUserRole.Participant)
                    {
                        certificatePath = Server.MapPath(oSession.certificate.UploadFilePath);
                        pdfCoordinates  = new CertificateDictionary().GetPdfCoordinatesFromDictionary(oSession.certificate.Type);
                    }
                    else
                    {
                        certificatePath = Server.MapPath(oSession.certificate1.UploadFilePath);
                        pdfCoordinates  = new CertificateDictionary().GetPdfCoordinatesFromDictionary(oSession.certificate1.Type);
                        oSession.IsVolunteerCertificateGenerated = true;
                    }
                    foreach (var pc in pdfCoordinates)
                    {
                        switch (pc.CertifiacteData)
                        {
                        case CertificateEnum.NameOfStudent:
                            pc.Text = participant.Name + " " + participant.FatherName + " " + participant.Family;
                            break;

                        case CertificateEnum.NameOfCoordinator:
                            pc.Text = oSession.school.coordinator_profile.First().CoordinatorName;
                            break;

                        case CertificateEnum.ProgrammYear:
                            pc.Text = DateTime.Now.Year + "";
                            break;

                        case CertificateEnum.TranningDate:
                            pc.Text = Util.DateConversion(oSession.ActualDateTime.Value.ToShortDateString(), "Hijri", "en-us");
                            break;

                        case CertificateEnum.TranningHour:
                            pc.Text = ConfigurationManager.AppSettings["TranningHours"];
                            break;

                        case CertificateEnum.NameOfVolunteer:
                            pc.Text = oSession.volunteer_profile.VolunteerName;
                            break;
                        }
                    }
                    string fontFilePath = Server.MapPath("~/fonts/Arabic Fonts/trado.ttf");
                    var    outputFile   = PdfGenerator.GenerateOnflyPdf(certificatePath, pdfCoordinates, fontFilePath);
                    if (session.SubmitButton == "viewcertificate")
                    {
                        EmailSender.SendSupportEmail("Student Template", participant.Email, outputFile);
                        oSession.session_participant.Where(x => x.ParticipantID == participant.Id).First().IsCertificateGenerated = true;
                    }
                    else
                    {
                        EmailSender.SendSupportEmail("Volunteer Template", oSession.volunteer_profile.VolunteerEmail, outputFile);
                    }
                }
            }
            oSession.IsActive = session.IsActive;
            if (session.Id == 0)
            {
                sessionRepo.Post(oSession);
            }
            else
            {
                sessionRepo.Put(oSession.Id, oSession);
            }
            return(RedirectToAction("Index"));
        }