public ActionResult Edit(Guid?id) { funder_profile funderModel = null; var countries = new CountryRepository().Get().Select(x => new SelectListItem { Text = x.Name, Value = x.Id + "" }).ToList(); ViewBag.countries = countries; 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; if (id == null) { funderModel = new funder_profile(); funderModel.IsActive = true; funderModel.Country = 1192; funderModel.PhoneNumber = "+966"; funderModel.FunderMobile = "+966"; } else { var funderRepo = new FunderRepository(); funderModel = funderRepo.GetByRowId(id.Value); funderModel.Password = EncryptionKeys.Decrypt(funderModel.user.Password); } return(View(funderModel)); }
private static void ApprovedBylevel(volunteer_profile volunteer, VolunteerRepository repository, volunteer_profile oVolunteer, ContextUser cu) { if (cu.EnumRole == EnumUserRole.Approver1) { oVolunteer.IsApprovedAtLevel1 = true; oVolunteer.ApprovedAtLevel1Comments = volunteer.ApprovedAtLevel1Comments; } if (cu.EnumRole == EnumUserRole.Approver2) { oVolunteer.IsApprovedAtLevel2 = true; oVolunteer.ApprovedAtLevel2Comments = volunteer.ApprovedAtLevel2Comments; } if (cu.EnumRole == EnumUserRole.Approver3) { oVolunteer.IsApprovedAtLevel3 = true; oVolunteer.ApprovedAtLevel3Comments = volunteer.ApprovedAtLevel3Comments; string password = EncryptionKeys.Decrypt(oVolunteer.user.Password); string url = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Login"; var bogusController = Util.CreateController <EmailTemplateController>(); EmailTemplateModel emodel = new EmailTemplateModel { Title = "Volunteer Approved", RedirectUrl = url, VolunteerName = oVolunteer.VolunteerName, UserName = oVolunteer.user.Username, Password = password }; string body = Util.RenderViewToString(bogusController.ControllerContext, "VolunteerApproved", emodel); EmailSender.SendSupportEmail(body, oVolunteer.VolunteerEmail); } repository.Put(oVolunteer.Id, oVolunteer); }
public ActionResult Edit(Guid?id) { 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; var distict = new CityRepository().Get().GroupBy(x => x.Region).Select(x => x.First()).Select(x => new SelectListItem { Text = x.Region + " (" + x.Region_ar + ")", Value = x.Region + "" }).ToList(); ViewBag.distictdd = distict; coordinator_profile coordinator = null; var su = Session["user"] as ContextUser; if (id == null) { coordinator = new coordinator_profile(); if (su.EnumRole == EnumUserRole.Coordinator) { coordinator.school = su.OUser.coordinator_profile.First().school; } else { coordinator.school = new school(); } coordinator.IsActive = true; coordinator.Password = Membership.GeneratePassword(8, 4); } else { var coordinatorRepo = new CoordinatorRepository(); coordinator = coordinatorRepo.GetByRowId(id.Value); coordinator.Password = EncryptionKeys.Decrypt(coordinator.user.Password); } return(View(coordinator)); }
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)); }
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); //} }
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 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")); }
private static void NewCoordinatorEmail(coordinator_profile coordinator) { 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 = coordinator.CoordinatorEmail, Password = EncryptionKeys.Decrypt(coordinator.user.Password), CoordinatorName = coordinator.CoordinatorName, User = coordinator.user.FirstName }; string body = Util.RenderViewToString(bogusController.ControllerContext, "CoordinatorProfile", model); EmailSender.SendSupportEmail(body, coordinator.CoordinatorEmail); }
public ActionResult Edit(funder_profile profile) { var funderRepo = new FunderRepository(); var accountRepo = new AccountRepository(); funder_profile funder = null; var cu = Session["user"] as ContextUser; if (profile.Id == 0) { if (accountRepo.EmailExist(profile.FunderEmail)) { var countries = new CountryRepository().Get().Select(x => new SelectListItem { Text = x.Name, Value = x.Id + "" }).ToList(); ViewBag.countries = countries; 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.EmailExist = true; return(View(profile)); } funder = new funder_profile(); funder.RowGUID = Guid.NewGuid(); funder.CreatedAt = DateTime.Now; funder.CreatedBy = cu.OUser.Id; funder.FunderEmail = profile.FunderEmail; } else { funder = funderRepo.Get(profile.Id); funder.UpdatedAt = DateTime.Now; funder.UpdatedBy = cu.OUser.Id; } var userRole = new RoleRepository().Get().Where(x => x.Code == (int)EnumUserRole.Funder).FirstOrDefault(); if (funder.FunderUserID == 0) { funder.user = new user { RowGuid = Guid.NewGuid(), Email = profile.FunderEmail, Username = profile.FunderEmail, RegistrationDate = DateTime.Now, FirstName = profile.FunderName, RoleId = userRole.Id, CreatedAt = DateTime.Now, ValidFrom = DateTime.Now, FirstLogin = false, IsMobileVerified = false, IsEmailVerified = false, CreatedBy = cu.OUser.Id, Password = EncryptionKeys.Encrypt(profile.Password) } } ; funder.FunderName = profile.FunderName; funder.FatherName = profile.FatherName; funder.FaimlyName = profile.FaimlyName; funder.FunderMobile = profile.FunderMobile; funder.Country = profile.Country; funder.PhoneNumber = profile.PhoneNumber; funder.IsActive = profile.IsActive; funder.user.IsLocked = !funder.IsActive; funder.PartnerType = profile.PartnerType; funder.TypeOfFunding = profile.TypeOfFunding; funder.City = profile.City; funder.NationId = profile.NationId; funder.FunderName1 = profile.FunderName1; funder.FatherName1 = profile.FatherName1; funder.FaimlyName1 = profile.FaimlyName1; funder.PhoneNumber1 = profile.PhoneNumber1; funder.NationId1 = profile.NationId1; funder.City1 = profile.City1; funder.PartenerWebsite = profile.PartenerWebsite; funder.Email1 = profile.Email1; if (profile.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 = funder.FunderEmail, Password = EncryptionKeys.Decrypt(funder.user.Password), FunderName = funder.FunderName, User = funder.user.FirstName }; string body = Util.RenderViewToString(bogusController.ControllerContext, "FunderProfile", model); EmailSender.SendSupportEmail(body, funder.FunderEmail); funderRepo.Post(funder); } else { funderRepo.Put(funder.Id, funder); } return(RedirectToAction("Index")); }