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")); }
// 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 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")); }