//[ValidateAntiForgeryToken]
        public ActionResult UpdatePassword(ResetPasswordViewModel model)
        {
            var su         = Session["user"] as ContextUser;
            var repository = new AccountRepository();

            if (su != null)
            {
                var user = repository.Get(su.OUser.Id);
                user.Password   = EncryptionKeys.Encrypt(model.Password);
                user.FirstLogin = true;
                repository.Put(user.Id, user);
            }
            if (su.EnumRole == EnumUserRole.SuperAdmin)
            {
                return(RedirectToAction("DashBoard", "Home"));
            }
            if (su.EnumRole == EnumUserRole.Approver1 || su.EnumRole == EnumUserRole.Approver2 || su.EnumRole == EnumUserRole.Approver3)
            {
                return(RedirectToAction("Index", "Supervisor"));
            }
            if (su.EnumRole == EnumUserRole.Coordinator)
            {
                return(RedirectToAction("CoordinatorProfile", "Coordinator"));
            }
            if (su.EnumRole == EnumUserRole.Participant)
            {
                return(RedirectToAction("ParticipantProfile", "Participant"));
            }
            if (su.EnumRole == EnumUserRole.Funder)
            {
                return(RedirectToAction("Index", "Report"));
            }
            return(View("Login"));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repository = new AccountRepository();
                var user       = repository.Get().FirstOrDefault(x => x.Email == model.Email);
                if (user != null)
                {
                    string newPassword = Membership.GeneratePassword(8, 2);
                    user.Password   = EncryptionKeys.Encrypt(newPassword);
                    user.FirstLogin = false;


                    string             url             = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Login";
                    var                bogusController = Util.CreateController <EmailTemplateController>();
                    EmailTemplateModel emodel          = new EmailTemplateModel {
                        Title = "Reset Your Password", RedirectUrl = url, UserName = user.Username, Password = newPassword, User = user.FirstName
                    };
                    string body = Util.RenderViewToString(bogusController.ControllerContext, "ResetPassword", emodel);
                    EmailSender.SendSupportEmail(body, user.Email);

                    repository.Put(user.Id, user);
                    ViewBag.message = General.PasswordResetEmailsent;
                }
                else
                {
                    ViewBag.message       = General.Usernotfound;
                    ViewBag.notfounderror = true;
                    return(View(model));
                }
            }

            model.Email = "";

            return(RedirectToAction("ResetPasswordConfirmation"));
        }
        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 EditUser(user user, HttpPostedFileBase file)
        {
            var cu = Session["user"] as ContextUser;
            AccountRepository repo = new AccountRepository();
            user oUser             = null;

            if (user.Id == 0)
            {
                oUser           = new user();
                oUser.RowGuid   = Guid.NewGuid();
                oUser.CreatedAt = DateTime.Now;
                oUser.CreatedBy = cu.OUser.Id;

                oUser.Password         = EncryptionKeys.Encrypt(user.Password);
                oUser.RegistrationDate = DateTime.Now;
            }
            else
            {
                oUser           = repo.Get(user.Id);
                oUser.UpdatedBy = cu.OUser.Id;
                oUser.UpdatedAt = DateTime.Now;
            }

            int[] rolesCode = { (int)EnumUserRole.SuperAdmin, (int)EnumUserRole.Approver1, (int)EnumUserRole.Approver2, (int)EnumUserRole.Approver3 };

            RoleRepository reporole = new RoleRepository();

            ViewBag.rolesdd = reporole.Get().Where(x => rolesCode.Contains(x.Code)).Select(x =>
                                                                                           new SelectListItem {
                Text = x.FrindlyName, Value = x.Id + ""
            }
                                                                                           ).ToList();

            if (oUser.Username != user.Username && repo.UserExist(user.Username))
            {
                ViewBag.userexist = true;
                return(View(user));
            }
            if (oUser.Email != user.Email && repo.EmailExist(user.Email))
            {
                ViewBag.emailexist = true;
                return(View(user));
            }
            oUser.Username  = user.Username;
            oUser.Email     = user.Email;
            oUser.FirstName = user.FirstName;
            oUser.LastName  = user.LastName;
            oUser.RoleId    = user.RoleId;
            if (file != null)
            {
                string fileName = "~/Uploads/ImageLibrary/" + Guid.NewGuid() + Path.GetExtension(file.FileName);
                string filePath = Server.MapPath(fileName);
                file.SaveAs(filePath);
                oUser.PhotoPath = fileName;
            }
            if (oUser.Id > 0)
            {
                repo.Put(oUser.Id, oUser);
            }
            else
            {
                string             url             = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
                var                bogusController = Util.CreateController <EmailTemplateController>();
                EmailTemplateModel model           = new EmailTemplateModel {
                    Title = "Account Registraion ", RedirectUrl = url, UserName = oUser.Username, Password = user.Password, User = user.FirstName
                };
                string body = Util.RenderViewToString(bogusController.ControllerContext, "UserProfile", model);

                EmailSender.SendSupportEmail(body, oUser.Email);
                repo.Post(oUser);
            }
            return(RedirectToAction("UserList"));
        }
        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"));
        }
        public ActionResult Edit(coordinator_profile profile)
        {
            var coordinatorRepo             = new CoordinatorRepository();
            var accountRepo                 = new AccountRepository();
            coordinator_profile coordinator = null;
            var  su       = Session["user"] as ContextUser;
            var  userRole = new RoleRepository().Get().FirstOrDefault(x => x.Code == (int)EnumUserRole.Coordinator);
            user ouser    = null;

            if (profile.Id == 0)
            {
                if (accountRepo.EmailExist(profile.CoordinatorEmail))
                {
                    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;
                    ViewBag.EmailExist = true;
                    if (su != null && su.EnumRole == EnumUserRole.Coordinator)
                    {
                        profile.school = su.OUser.coordinator_profile.First().school;
                    }
                    return(View(profile));
                }
                coordinator           = new coordinator_profile();
                coordinator.RowGuid   = Guid.NewGuid();
                coordinator.CreatedAt = DateTime.Now;
                coordinator.CreatedBy = su.OUser.Id;

                coordinator.IsPrimery  = true;
                coordinator.FirstLogin = true;
                ouser = new user
                {
                    RowGuid = Guid.NewGuid(),

                    Username         = profile.CoordinatorEmail,
                    RegistrationDate = DateTime.Now,
                    FirstName        = "",
                    RoleId           = userRole.Id,
                    CreatedAt        = DateTime.Now,
                    FirstLogin       = false,
                    ValidFrom        = DateTime.Now,
                    IsMobileVerified = false,
                    IsEmailVerified  = false,
                    CreatedBy        = su.OUser.Id
                };

                coordinator.user = ouser;

                coordinator.IsActive      = profile.IsActive;
                coordinator.user.IsLocked = !coordinator.IsActive;
                if (su.EnumRole == EnumUserRole.SuperAdmin)
                {
                    coordinator.school           = new school();
                    coordinator.school.RowGuid   = Guid.NewGuid();
                    coordinator.school.CreatedBy = su.OUser.Id;
                    coordinator.school.CreatedAt = DateTime.Now;
                    coordinator.school.user      = ouser;

                    coordinator.school.SchoolName = profile.school.SchoolName;
                    coordinator.school.City       = profile.school.City;
                    coordinator.school.District   = profile.school.District;
                    coordinator.school.Region     = profile.school.Region;
                    coordinator.school.Status     = "Initial";
                }

                else
                {
                    coordinator.ParentId = su.OUser.coordinator_profile.First().Id;
                    coordinator.SchoolId = su.OUser.coordinator_profile.First().school.Id;
                    //coordinator.school.Status = "Approved";
                    coordinator.CoordinatorName = su.OUser.coordinator_profile.First().CoordinatorName;
                }
            }
            else
            {
                coordinator           = coordinatorRepo.Get(profile.Id);
                coordinator.UpdatedAt = DateTime.Now;
                coordinator.UpdatedBy = su.OUser.Id;
                coordinator.IsActive  = profile.IsActive;

                coordinator.user.Email    = profile.CoordinatorEmail;
                coordinator.user.Username = profile.CoordinatorEmail;


                coordinator.user.Password = EncryptionKeys.Encrypt(profile.Password);
                if (su.EnumRole == EnumUserRole.Coordinator)
                {
                    coordinator.ParentId      = su.OUser.coordinator_profile.First().Id;
                    coordinator.SchoolId      = su.OUser.coordinator_profile.First().school.Id;
                    coordinator.school.Status = "Approved";
                }
                else
                {
                    coordinator.school.SchoolName = profile.school.SchoolName;
                    coordinator.school.City       = profile.school.City;
                    coordinator.school.District   = profile.school.District;
                    coordinator.school.Region     = profile.school.Region;
                    if (coordinator.school.Status == "Pending")
                    {
                        coordinator.school.Status = "Approved";
                        NewCoordinatorEmail(coordinator);
                    }
                }
            }
            coordinator.user.Email       = profile.CoordinatorEmail;
            coordinator.CoordinatorEmail = profile.CoordinatorEmail;
            coordinator.user.Username    = profile.CoordinatorEmail;
            coordinator.user.Password    = EncryptionKeys.Encrypt(profile.Password);
            if (profile.Id == 0)
            {
                //  coordinator.school.Status = "Pending";

                if (su.EnumRole == EnumUserRole.Coordinator)
                {
                    NewCoordinatorEmail(coordinator);
                }
                else
                {
                    SchoolRegistrationEmail(coordinator);
                }
                coordinatorRepo.Post(coordinator);
            }
            else
            {
                coordinatorRepo.Put(coordinator.Id, coordinator);
            }
            return(RedirectToAction("Index"));
        }
        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"));
        }
Example #9
0
        public ActionResult VolunteerProfile(volunteer_profile volunteer, HttpPostedFileBase file)
        {
            var cu         = Session["user"] as ContextUser;
            var repository = new VolunteerRepository();
            volunteer_profile oVolunteer = null;

            if (cu != null)
            {
                oVolunteer = repository.GetByGoogleId(cu.GoogleId) ?? repository.GetByLinkedInId(cu.LinkedInId);
            }

            if (oVolunteer == null)
            {
                oVolunteer            = new volunteer_profile();
                oVolunteer.CreatedAt  = DateTime.Now;
                oVolunteer.CreatedBy  = 1;
                oVolunteer.FirstLogin = true;
                oVolunteer.RowGuid    = Guid.NewGuid();
            }
            else
            {
                oVolunteer.UpdatedAt = DateTime.Now;
                oVolunteer.UpdatedBy = 1;
            }
            oVolunteer.NationalID             = volunteer.NationalID;
            oVolunteer.VolunteerName          = volunteer.VolunteerName;
            oVolunteer.GoogleSigninId         = cu != null ? cu.GoogleId : "";
            oVolunteer.LinkedInSignInId       = cu != null ? cu.LinkedInId : "";
            oVolunteer.VolunteerEmail         = volunteer.VolunteerEmail;
            oVolunteer.VolunteerMobile        = volunteer.VolunteerMobile;
            oVolunteer.Gender                 = volunteer.Gender;
            oVolunteer.DateOfBirth            = volunteer.DateOfBirth;
            oVolunteer.AcademicQualification  = volunteer.AcademicQualification;
            oVolunteer.AcademicQualification1 = volunteer.AcademicQualification1;
            oVolunteer.AcademicQualification2 = volunteer.AcademicQualification2;
            oVolunteer.CompanyName            = volunteer.CompanyName;
            oVolunteer.VolunteerExperince1    = volunteer.VolExp == "Yes" ? string.Join(",", volunteer.SelectedExp == null ? new string[] { } : volunteer.SelectedExp) : "";
            oVolunteer.Telephone              = volunteer.Telephone;
            oVolunteer.Region                 = volunteer.Region;
            oVolunteer.City = volunteer.City;
            oVolunteer.VolunteerActivity1 = volunteer.VolunteerActivity1;
            oVolunteer.VolunteerActivity2 = volunteer.VolunteerActivity2;
            oVolunteer.VolunteerActivity3 = volunteer.VolunteerActivity3;
            oVolunteer.HasTOTCertificate  = volunteer.HasTOTCertificate;
            oVolunteer.OtherCertificate1  = volunteer.OtherCertificate1;
            oVolunteer.OtherCertificate2  = volunteer.OtherCertificate2;
            oVolunteer.OtherCertificate3  = volunteer.OtherCertificate3;
            oVolunteer.City = volunteer.City;
            if (file != null)
            {
                string fileName = "~/Uploads/ImageLibrary/" + Guid.NewGuid() + Path.GetExtension(file.FileName);
                string filePath = Server.MapPath(fileName);
                file.SaveAs(filePath);
                oVolunteer.PhotoPath = fileName;
            }
            oVolunteer.LinkedIn          = volunteer.LinkedIn;
            oVolunteer.IsProfileComplete = true;
            if (oVolunteer.Id > 0)
            {
                repository.Put(oVolunteer.Id, oVolunteer);
            }
            else
            {
                var userRole = new RoleRepository().Get().Where(x => x.Code == (int)EnumUserRole.Volunteer)
                               .FirstOrDefault();
                string password = Membership.GeneratePassword(8, 4);
                oVolunteer.user = new user()
                {
                    RowGuid          = Guid.NewGuid(),
                    Email            = oVolunteer.VolunteerEmail,
                    Username         = oVolunteer.VolunteerEmail,
                    RegistrationDate = DateTime.Now,
                    FirstName        = oVolunteer.VolunteerName,
                    RoleId           = userRole.Id,
                    CreatedAt        = DateTime.Now,
                    ValidFrom        = DateTime.Now,
                    FirstLogin       = false,
                    IsMobileVerified = false,
                    IsEmailVerified  = false,
                    CreatedBy        = cu != null ? cu.OUser.Id : 0,
                    Password         = EncryptionKeys.Encrypt(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 Registration",
                    RedirectUrl   = url,
                    VolunteerName = oVolunteer.VolunteerName
                };
                string body =
                    Util.RenderViewToString(bogusController.ControllerContext, "VolunteerRegister", emodel);
                EmailSender.SendSupportEmail(body, oVolunteer.VolunteerEmail);

                repository.Post(oVolunteer);

                cu = new ContextUser
                {
                    OUser = new user
                    {
                        Username = oVolunteer.VolunteerName,
                        Email    = oVolunteer.VolunteerEmail,
                        Id       = oVolunteer.UserId
                    },
                    EnumRole   = EnumUserRole.Volunteer,
                    FullName   = "",
                    ProfileUrl = ""
                };
                Session["user"] = cu;
            }
            if (Request["editprofile"] != null)
            {
                return(RedirectToAction("VolunteerProfile", new { editprofile = true }));
            }

            return(RedirectToAction("VolunteerProfile"));
        }