public override void OnActionExecuting(ActionExecutingContext filterContext) { if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.Identity.AuthenticationType == "Forms") { if (SessionWrapper.UserAccount == null) { var objAccountRepository = new AccountRepository(); if (objAccountRepository.SetAccountByUser(Convert.ToInt32(HttpContext.Current.User.Identity.Name))) { if (IsAdmin == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.Admin.GetHashCode()) { RedirectAdminLogin(filterContext); } if (IsUser == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.User.GetHashCode()) { RedirectUserLogin(filterContext); } } } else { if (IsAdmin == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.Admin.GetHashCode()) { RedirectAdminLogin(filterContext); } if (IsUser == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.User.GetHashCode()) { RedirectUserLogin(filterContext); } } } else { RedirectAdminLogin(filterContext); } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var objController = filterContext.RouteData.Values["Controller"]; var objAction = filterContext.RouteData.Values["Action"]; int UserId = 0; if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.Identity.AuthenticationType == "Forms") { UserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); if (SessionWrapper.UserAccount == null) { var objAccountRepository = new AccountRepository(); if (objAccountRepository.SetAccountByUser(UserId)) { if (ActionAccess != ActionUserAccessEnum.Default && ActionAccess != ActionUserAccessEnum.AdminOnly) { CheckRoleUserAccess(filterContext, new UserAccessViewModel() { Url = objController.ToString() }, SessionWrapper.UserAccount.RoleId); } } } else { if (ActionAccess != ActionUserAccessEnum.Default && ActionAccess != ActionUserAccessEnum.AdminOnly) { CheckRoleUserAccess(filterContext, new UserAccessViewModel() { Url = objController.ToString() }, SessionWrapper.UserAccount.RoleId); } } } else { RedirectUnAuthorizedUserLogin(filterContext); } base.OnActionExecuting(filterContext); }
public ActionResult ProfileEdit(int id, RegistrationUpdateViewModel objUpdateEntity) { var objRegistrationRepository = new RegistrationRepository(); string fileName = string.Empty; string oldFileName = string.Empty; if (ModelState.IsValid) { #region FileUpload if (objUpdateEntity.UploadPhoto != null) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objUpdateEntity.UploadPhoto.FileName); oldFileName = objUpdateEntity.PhotoName; objUpdateEntity.PhotoName = fileName; } #endregion objUpdateEntity.FirstName = objUpdateEntity.FirstName.Trim(); objUpdateEntity.LastName = objUpdateEntity.LastName.Trim(); objUpdateEntity.PhotoName = objUpdateEntity.PhotoName; objUpdateEntity.DateOfBirth = objUpdateEntity.DateOfBirth; objUpdateEntity.Location = objUpdateEntity.Location.Trim(); objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim(); objUpdateEntity.RegistrationId = id; var objEntity = new RegistrationViewModel() { RegistrationId = objUpdateEntity.RegistrationId, UserId = objUpdateEntity.UserId, FirstName = objUpdateEntity.FirstName, LastName = objUpdateEntity.LastName, PhotoName = objUpdateEntity.PhotoName, DateOfBirth = objUpdateEntity.DateOfBirth, Gender = objUpdateEntity.Gender, Location = objUpdateEntity.Location, MobileNumber = objUpdateEntity.MobileNumber }; objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { #region FileUpload //delete old file //file name if (objUpdateEntity.UploadPhoto != null) { if (!string.IsNullOrEmpty(objUpdateEntity.UploadPhoto.FileName)) { ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), oldFileName)); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName); // WebImage.Save() objUpdateEntity.UploadPhoto.SaveAs(path); } #endregion this.Flash("Success", "My Profile updated successfully "); //reload admin profile SessionWrapper.UserAccount = null; AccountRepository objAccountRepository = new AccountRepository(); objAccountRepository.SetAccountByUser(objEntity.UserId); return RedirectToAction("Dashboard", "Admin"); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("Error", "My Profile failed to update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("Warning", "It already exist"); } } return View(objUpdateEntity); }