public ActionResult Business(int?p, string search) { using (UnitOfWorkManager.NewUnitOfWork()) { var pageIndex = p ?? 1; var allBusinesses = string.IsNullOrEmpty(search) ? _businessService.GetAll(pageIndex, SiteConstants.Instance.AdminListPageSize) : _businessService.SearchBusiness(search, pageIndex, SiteConstants.Instance.AdminListPageSize); var listViewModel = new BusinessListViewModel { Businesses = allBusinesses, PageIndex = pageIndex, TotalCount = allBusinesses.TotalCount, Search = search, TotalPages = allBusinesses.TotalPages }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; var viewModel = new BusinessViewModel { _listViewModel = listViewModel, _stateViewModel = statesViewModel }; return(View(viewModel)); } }
public ActionResult Register() { if (SettingsService.GetSettings().RegistrationEnabled == true) { using (UnitOfWorkManager.NewUnitOfWork()) { var user = MembershipService.CreateEmptyUser(); var viewModel = new MemberAddViewModel { Email = user.Email, Password = user.Password, AllRoles = RoleService.AllRoles(), FirstName = user.FirstName, LastName = user.LastName, City = user.City, State = user.State }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; viewModel._stateViewModel = statesViewModel; // See if a return url is present or not and add it var returnUrl = Request["ReturnUrl"]; if (!string.IsNullOrEmpty(returnUrl)) { viewModel.ReturnUrl = returnUrl; } return(View(viewModel)); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit() { using (UnitOfWorkManager.NewUnitOfWork()) { var loggedOnUserId = LoggedOnReadOnlyUser.Id; //var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; //var permissions = RoleService.GetPermissions(null, UsersRole); // Check is has permissions //if (UserIsAdmin || loggedOnUserId == id || permissions[SiteConstants.Instance.PermissionEditMembers].IsTicked) if (loggedOnUserId != null) { var user = MembershipService.Get(loggedOnUserId); var roles = MembershipService.GetRolesForUser(user.Email); var viewModel = PopulateMemberViewModel(user); viewModel.role = roles[0]; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; viewModel._stateViewModel = statesViewModel; viewModel.user = user; return(View(viewModel)); } return(ErrorToHomePage("Updated profile is disabled for now")); } }
public ActionResult StateGrid() { var state_view_model = new StatesViewModel(); state_view_model.States = db.States.ToList(); return(View(state_view_model)); }
// GET: States/Create public ActionResult StateDetail(int stateID) { var state_view_model = new StatesViewModel(); state_view_model.States = db.States.Where(x => x.Id == stateID) .Include(c => c.Counties.Select(e => e.Incidents)).ToList(); return(View(state_view_model)); }
public List <StatesViewModel> StatesList() { List <States> state = _commonListRepository.StatesList(); List <StatesViewModel> statesVM = new List <StatesViewModel>(); foreach (States s in state) { StatesViewModel sVM = new StatesViewModel(); sVM.StateId = s.StateId; sVM.StateCode = s.StateCode; sVM.StateName = s.StateName; statesVM.Add(sVM); } return(statesVM); }
public ActionResult EditMembershipUser(Guid id) { using (UnitOfWorkManager.NewUnitOfWork()) { var membershipUser = MembershipService.Get(id); var membershipUserList = MembershipService.GetAll(); var memberRole = MembershipService.GetRolesForUser(membershipUser.Email); var listViewModel = new MembershipUserListViewModel { NonPagedMembershipUsers = membershipUserList.ToList() }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; var viewModel = new MembershipUserViewModel { MembershipUserId = membershipUser.Id, EditEmail = membershipUser.Email, EditFirstName = membershipUser.FirstName, EditLastName = membershipUser.LastName, EditCity = membershipUser.City, EditState = membershipUser.State, EditDisplayName = membershipUser.DisplayName, EditActive = membershipUser.Active, Avatar = membershipUser.Avatar, _listViewModel = listViewModel, _statesViewModel = statesViewModel, //add user details here Role = memberRole[0] }; if (membershipUser.Businesses != null) { viewModel.RegisteredBusinessCount = membershipUser.Businesses.Count().ToString(); } return(View(viewModel)); } }
public ActionResult MembershipUser(int?p, string search) { var pageIndex = p ?? 1; var allMemberships = string.IsNullOrEmpty(search) ? MembershipService.GetAll(pageIndex, SiteConstants.Instance.AdminListPageSize) : MembershipService.SearchMembers(search, pageIndex, SiteConstants.Instance.AdminListPageSize); var listViewModel = new MembershipUserListViewModel { MembershipUsers = allMemberships, PageIndex = pageIndex, TotalCount = allMemberships.TotalCount, Search = search, TotalPages = allMemberships.TotalPages }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; var user = MembershipService.CreateEmptyUser(); var adminViewModel = new AdminMemberAddViewModel { Email = user.Email, AllRoles = RoleService.AllRoles(), FirstName = user.FirstName, LastName = user.LastName }; adminViewModel._stateViewModel = statesViewModel; var viewModel = new MembershipUserViewModel { _listViewModel = listViewModel, _adminMemberAddViewModel = adminViewModel }; return(View(viewModel)); }
public ActionResult UpdateBusiness(UpdateBusinessViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var business = _businessService.Get(viewModel.Id); //need to use slug/or check is guid is modified if (business != null) { var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; var admin = MembershipService.Get(loggedOnUserId); var settings = SettingsService.GetSettings(); var allMemberships = MembershipService.GetAll(); //query for User dropdown var allMembersViewModel = allMemberships.Select(ViewModelMapping.UserToSingleMemberListViewModel).ToList(); //Load dropdowns: ListBooleanViewModel booleanViewModel = new ListBooleanViewModel() { ListBoolean = SettingsService.ListOfBoolean().ToList() }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; AllClassificationsViewModel classificationViewModel = new AllClassificationsViewModel() { allClassifications = _classificationService.GetAllClassifications().ToList() }; AllMembershipLevelViewModel membershipLevelViewModel = new AllMembershipLevelViewModel() { allMembershipLevels = _membershipLevelService.GetAllMembershipLevels().ToList() }; AllMembersListViewModel membersListViewModel = new AllMembersListViewModel() { AllMembershipUsersList = allMembersViewModel }; // Sort image out first if (viewModel.Files != null) { // Before we save anything, check the user already has an upload folder and if not create one var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, business.Id)); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } // Loop through each file and get the file info and save to the users folder and Db var file = viewModel.Files[0]; if (file != null) { // If successful then upload the file var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, true); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; return(View(viewModel)); } // Save avatar to user business.Avatar = uploadResult.UploadedFileName; } } viewModel.Avatar = business.Avatar; viewModel._booleanViewModel = booleanViewModel; viewModel._stateViewModel = statesViewModel; viewModel._allClassificationsViewModel = classificationViewModel; viewModel._allMembershipLevelViewModel = membershipLevelViewModel; viewModel._allMembersListViewModel = membersListViewModel; business.Id = viewModel.Id; business.Name = viewModel.Name; //Need to check for duplicates (look at edit DisplayName) business.MailingAddress = viewModel.MailingAddress; business.MailingCity = viewModel.MailingCity; business.MailingState = viewModel.MailingState; business.MailingZipcode = viewModel.MailingZipcode; business.PhysicalAddress = viewModel.PhysicalAddress; business.PhysicalCity = viewModel.PhysicalCity; business.PhysicalState = viewModel.PhysicalState; business.PhysicalZipcode = viewModel.PhysicalZipcode; business.Active = viewModel.Active; business.Completed = viewModel.Completed; business.Description = viewModel.Description; business.Phone = viewModel.Phone; business.WebAddress = viewModel.WebAddress; if (viewModel.Classification_Id != null) { var classification = _classificationService.GetById(viewModel.Classification_Id); business.Classification = classification; } if (viewModel.MembershipLevel_Id != null) { var membershipLevel = _membershipLevelService.GetById(viewModel.MembershipLevel_Id); business.MembershipLevel = membershipLevel; } if (viewModel.MembershipUser_Id != null) { var membershipUser = MembershipService.Get(viewModel.MembershipUser_Id); business.User = membershipUser; } try { _businessService.AdminBusinessUpdated(business, admin); unitOfWork.Commit(); ShowMessage(new AdminGenericMessageViewModel { Message = "Saving the business information was successful.", MessageType = GenericMessages.success }); } catch (Exception ex) { unitOfWork.Rollback(); //LoggingService.Error(ex); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Saving the business information failed. Try again or contact Administrator.", MessageType = GenericMessages.danger }; } return(View(viewModel)); } TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Saving the business information failed. Try again or contact Administrator.", MessageType = GenericMessages.danger }; return(RedirectToAction("Index", "Admin", new { area = "Admin" })); } }
public ActionResult UpdateBusiness(Guid id) { using (UnitOfWorkManager.NewUnitOfWork()) { var business = _businessService.Get(id); if (business != null) { var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; var settings = SettingsService.GetSettings(); var allMemberships = MembershipService.GetAll(); var allMembersViewModel = allMemberships.Select(ViewModelMapping.UserToSingleMemberListViewModel).ToList(); ListBooleanViewModel booleanViewModel = new ListBooleanViewModel() { ListBoolean = SettingsService.ListOfBoolean().ToList() }; StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; AllClassificationsViewModel classificationViewModel = new AllClassificationsViewModel() { allClassifications = _classificationService.GetAllClassifications().ToList() }; AllMembershipLevelViewModel membershipLevelViewModel = new AllMembershipLevelViewModel() { allMembershipLevels = _membershipLevelService.GetAllMembershipLevels().ToList() }; AllMembersListViewModel membersListViewModel = new AllMembersListViewModel() { AllMembershipUsersList = allMembersViewModel }; UpdateBusinessViewModel viewModel = new UpdateBusinessViewModel() { Id = business.Id, Name = business.Name, MailingAddress = business.MailingAddress, MailingCity = business.MailingCity, MailingState = business.MailingState, MailingZipcode = business.MailingZipcode, PhysicalAddress = business.PhysicalAddress, PhysicalCity = business.PhysicalCity, PhysicalState = business.PhysicalState, PhysicalZipcode = business.PhysicalZipcode, Active = business.Active, Completed = business.Completed, Description = business.Description, Avatar = business.Avatar, Phone = business.Phone, WebAddress = business.WebAddress, _booleanViewModel = booleanViewModel, _stateViewModel = statesViewModel, _allClassificationsViewModel = classificationViewModel, _allMembershipLevelViewModel = membershipLevelViewModel, _allMembersListViewModel = membersListViewModel }; if (business.Classification != null) { viewModel.Classification_Id = business.Classification.Id; } if (business.MembershipLevel != null) { viewModel.MembershipLevel_Id = business.MembershipLevel.Id; } if (business.User != null) { viewModel.MembershipUser_Id = business.User.Id; } return(View(viewModel)); } TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Loading the business information failed. Try again or contact Administrator.", MessageType = GenericMessages.success }; return(RedirectToAction("Index", "Admin", new { area = "Admin" })); } }
public ActionResult AddBusiness(BusinessViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; var admin = MembershipService.Get(loggedOnUserId); var settings = SettingsService.GetSettings(); var businessToAdd = new Business { Name = viewModel.Name, PhysicalCity = viewModel.PhysicalCity, PhysicalState = viewModel.PhysicalState, Active = false, Completed = false }; StatesViewModel statesViewModel = new StatesViewModel() //Load static State dropdown { allStates = SettingsService.ListOfStates().ToList() }; viewModel._stateViewModel = statesViewModel; //ToDo: //1)check if name is duplicate //2) //var createStatus = _businessService.AdminCreateBusiness(businessToAdd, loggedOnUserId); var business = _businessService.GetByName(viewModel.Name); if (business == null) { try { business = _businessService.Add(businessToAdd); _businessService.AdminBusinessAdded(businessToAdd, admin); unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Business Added.", MessageType = GenericMessages.success }; return(RedirectToAction("UpdateBusiness", "AdminBusiness", new { id = business.Id })); } catch (Exception ex) { unitOfWork.Rollback(); //LoggingService.Error(ex); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Adding a business failed.", MessageType = GenericMessages.danger }; } } else { TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Duplicate business name. Add failed.", MessageType = GenericMessages.danger }; } } return(View(viewModel)); }
public ActionResult EditMembershipUser(MembershipUserViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; //Admin Id var admin = MembershipService.Get(loggedOnUserId); //Admin doing update var user = MembershipService.Get(viewModel.MembershipUserId); //User to update var membershipUserList = MembershipService.GetAll(); //Dashboard #'s var memberRole = MembershipService.GetRolesForUser(user.Email); //User's role StatesViewModel statesViewModel = new StatesViewModel() //Load static State dropdown { allStates = SettingsService.ListOfStates().ToList() }; viewModel._statesViewModel = statesViewModel; var listViewModel = new MembershipUserListViewModel //Dashboard #'s { NonPagedMembershipUsers = membershipUserList.ToList() }; viewModel._listViewModel = listViewModel; viewModel.Role = memberRole[0]; if (viewModel.EditDisplayName.Count() < 3) //Display Name must have 3 Characters { TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Username must have atleast 3 characters.", MessageType = GenericMessages.danger }; return(View(viewModel)); } // Sort image out first if (viewModel.Files != null) { // Before we save anything, check the user already has an upload folder and if not create one var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, user.Id)); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } // Loop through each file and get the file info and save to the users folder and Db var file = viewModel.Files[0]; if (file != null) { // If successful then upload the file var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, true); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; return(View(viewModel)); } // Save avatar to user user.Avatar = uploadResult.UploadedFileName; } } // Set the users Avatar for the confirmation page viewModel.Avatar = user.Avatar; user.FirstName = viewModel.EditFirstName; user.LastName = viewModel.EditLastName; user.City = viewModel.EditCity; user.State = viewModel.EditState; if (viewModel.EditDisplayName != user.DisplayName) { if (MembershipService.GetUserByDisplayName(viewModel.EditDisplayName) != null) { unitOfWork.Rollback(); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "This display name is already taken. Please choose another display name.", MessageType = GenericMessages.danger }; return(View(viewModel)); } user.DisplayName = viewModel.EditDisplayName; } if (viewModel.EditEmail != user.Email) { if (MembershipService.GetUserByEmail(viewModel.EditEmail) != null) { unitOfWork.Rollback(); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "This email is already taken. Please choose another email.", MessageType = GenericMessages.danger }; return(View(viewModel)); } user.Email = viewModel.EditEmail; } try { MembershipService.AdminProfileUpdated(user, admin); unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = "Profile updated", MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); //LoggingService.Error(ex); TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel { Message = ex.ToString(), MessageType = GenericMessages.danger }; } return(View(viewModel)); } }
public StatesPage() { InitializeComponent(); BindingContext = _viewModel = new StatesViewModel(); }
public ActionResult Edit(MemberFrontEndEditViewModel userModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty; //var permissions = RoleService.GetPermissions(null, UsersRole); // Check is has permissions if (loggedOnUserId == userModel.Id) //|| permissions[SiteConstants.Instance.PermissionEditMembers].IsTicked) { // Get the user from DB var user = MembershipService.Get(userModel.Id); StatesViewModel statesViewModel = new StatesViewModel() { allStates = SettingsService.ListOfStates().ToList() }; userModel._stateViewModel = statesViewModel; if (userModel.DisplayName.Count() < 3) { //Check if user name is taken ***** ShowMessage(new GenericMessageViewModel { Message = "Username must have atleast 3 characters.", MessageType = GenericMessages.danger }); return(View(userModel)); } // Sort image out first if (userModel.Files != null) { // Before we save anything, check the user already has an upload folder and if not create one var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, LoggedOnReadOnlyUser.Id)); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } // Loop through each file and get the file info and save to the users folder and Db var file = userModel.Files[0]; if (file != null) { // If successful then upload the file var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, true); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; return(View(userModel)); } // Save avatar to user user.Avatar = uploadResult.UploadedFileName; } } // Set the users Avatar for the confirmation page userModel.Avatar = user.Avatar; // Update other users properties //user.Location = _bannedWordService.SanitiseBannedWords(userModel.City, bannedWords); user.City = userModel.City; user.State = userModel.State; // User is trying to change username, need to check if a user already exists // with the username they are trying to change to var changedUsername = false; //var sanitisedUsername = _bannedWordService.SanitiseBannedWords(userModel.UserName, bannedWords); if (userModel.DisplayName != user.DisplayName) { if (MembershipService.GetUserByDisplayName(userModel.DisplayName) != null) { unitOfWork.Rollback(); ModelState.AddModelError(string.Empty, "Duplicate Display Name"); return(View(userModel)); } user.DisplayName = userModel.DisplayName; changedUsername = true; } // User is trying to update their email address, need to // check the email is not already in use //if (userModel.Email != user.Email) //{ // // Add get by email address // if (MembershipService.GetUserByEmail(userModel.Email) != null) // { // unitOfWork.Rollback(); // ModelState.AddModelError(string.Empty, "Duplicate Email."); // return View(userModel); // } // user.Email = userModel.Email; //} try { MembershipService.ProfileUpdated(user); unitOfWork.Commit(); ShowMessage(new GenericMessageViewModel { Message = "Profile updated", MessageType = GenericMessages.success }); if (changedUsername) //This is email (not implimented yet....) { // User has changed their username so need to log them in // as there new username of var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { var authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (authTicket != null) { var newFormsIdentity = new FormsIdentity(new FormsAuthenticationTicket(authTicket.Version, user.Email, authTicket.IssueDate, authTicket.Expiration, authTicket.IsPersistent, authTicket.UserData)); var roles = authTicket.UserData.Split("|".ToCharArray()); var newGenericPrincipal = new GenericPrincipal(newFormsIdentity, roles); System.Web.HttpContext.Current.User = newGenericPrincipal; } } // sign out current user FormsAuthentication.SignOut(); // Abandon the session Session.Abandon(); // Sign in new user FormsAuthentication.SetAuthCookie(user.Email, false); } } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError(string.Empty, "Error updating profile"); } return(View(userModel)); } return(ErrorToHomePage("Profile disabled")); } }