public JsonResult RefAgencyDelete(string id) { Guid org = new Guid(id); int SuccID = db_Ref.DeleteT_OE_ORGANIZATION(org); //now delete from Azure AzureSearch.DeleteSearchIndexAgency(id); string response = "Success"; if (SuccID == -1) { response = "Cannot delete agency because agency users exist."; } else if (SuccID == -2) { response = "Cannot delete agency because agency projects exist."; } else if (SuccID == -3) { response = "Cannot delete agency because agency enterprise services exist."; } return(Json(response)); }
public JsonResult ProjectsDelete(IEnumerable <Guid> RecordDeletebyId) { int UserIDX = db_Accounts.GetUserIDX(); if (RecordDeletebyId == null) { return(Json("No record selected to delete")); } else { foreach (var id in RecordDeletebyId) { //CHECK PERMISSIONS T_OE_PROJECTS p = db_EECIP.GetT_OE_PROJECTS_ByIDX(id); if (p != null) { if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgIDX(db_Accounts.GetUserIDX(), p.ORG_IDX.ConvertOrDefault <Guid>())) { int SuccID = db_EECIP.DeleteT_OE_PROJECTS(id); if (SuccID > 0) { //SUCCESS - now delete from Azure AzureSearch.DeleteSearchIndexProject(id); return(Json("Success")); } } } } //if got this far, general error return(Json("Unable to delete project.")); } }
public ActionResult EditPost(vmForumTopicCreate model) { //get topic being edited Topic _topic = db_Forum.GetTopic_ByID(model.TopicId); if (_topic != null) { // Update the Topic db_Forum.InsertUpdateTopic(model, 0); Guid?newPostID = db_Forum.InsertUpdatePost(model.Id, model.Content, null, null, null, null, null, null, null, null, null, true); // 7. Tag handling db_Forum.DeleteTopicTags(model.TopicId, "Topic Tag"); foreach (string feature in model.SelectedTags ?? new List <string>()) { db_Forum.InsertUpdateTopicTags(model.TopicId, "Topic Tag", feature); } // 11. Update Azure search AzureSearch.PopulateSearchIndexForumTopic(model.TopicId); } return(RedirectToAction("ShowTopic", "Forum", new { slug = _topic.Slug })); }
public ActionResult Search2(string q, string facetDataType, string facetMedia, string facetRecordSource, string facetAgency, string facetState, string facetOrgType, string facetTags, string facetPopDensity, string facetRegion, string facetStatus, string activeTab, string currentPage, string sortType, string sortDir) { ; var model = new vmDashboardSearch { q = q, facetDataType = facetDataType, facetMedia = facetMedia, facetRecordSource = facetRecordSource, facetAgency = facetAgency, facetState = facetState, facetOrgType = facetOrgType, facetTags = facetTags, facetPopDensity = facetPopDensity, facetRegion = facetRegion, facetStatus = facetStatus, activeTab = activeTab ?? "1", currentPage = currentPage.ConvertOrDefault <int?>() ?? 1, sortType = sortType, sortDir = sortDir, searchResults = AzureSearch.QuerySearchIndex(q, facetDataType, facetMedia, facetRecordSource, facetAgency, facetState, facetOrgType, facetTags, facetPopDensity, facetRegion, facetStatus, currentPage.ConvertOrDefault <int?>() ?? 1, sortType, sortDir) }; //log search //if (!string.IsNullOrEmpty(q)) // db_Ref.InsertT_OE_SYS_SEARCH_LOG(q.ToUpper().Trim()); return(View(model)); }
public ActionResult SearchAdminSynonymEdit(vmAdminSearch model) { int UserIDX = db_Accounts.GetUserIDX(); int SuccID = 0; if (model.edit_synonym_text != null) { SuccID = db_Ref.InsertUpdatetT_OE_REF_SYNONYMS(model.edit_synonym_idx, model.edit_synonym_text, UserIDX); } else if (model.edit_synonym_bulk != null) { foreach (string row in model.edit_synonym_bulk.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)) { SuccID = db_Ref.InsertUpdatetT_OE_REF_SYNONYMS(null, row, UserIDX); } } if (SuccID > 0) { AzureSearch.UploadSynonyms(); AzureSearch.EnableSynonyms(); TempData["Success"] = "Update successful."; } else { TempData["Error"] = "Error updating data."; } //return View(model); return(RedirectToAction("SearchAdmin")); }
public ActionResult Index(vmDashboardSearch model) { //int UserIDX = db_Accounts.GetUserIDX(); model.searchResults = AzureSearch.QuerySearchIndex(model.searchStr); return(View(model)); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { //IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); //IConfigurationRoot configuration = builder.Build(); //KeyExtraction keyExtraction = new KeyExtraction(); List <string> keys = await KeyExtraction.CallWebAPIAsync(turnContext.Activity.Text.Trim()); var documentModels = await AzureSearch.searchAzureSqlIndexer(keys); //await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {turnContext.Activity.Text}"), cancellationToken); await turnContext.SendActivityAsync(MessageFactory.Text(documentModels.Count != 0 ? documentModels[0].docLink : "We did not find any referenced document"), cancellationToken); }
public ActionResult SearchAdminDeleteIndex() { try { AzureSearch.DeleteSearchIndex(); TempData["Success"] = "Search index deleted."; } catch (Exception ex) { TempData["Error"] = ex.ToString().SubStringPlus(0, 100); } return(RedirectToAction("SearchAdmin", "Admin")); }
public ActionResult AgencyEdit(vmDashboardAgency model) { int UserIDX = db_Accounts.GetUserIDX(); //CHECK PERMISSIONS if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgIDX(UserIDX, model.agency.ORG_IDX.ConvertOrDefault <Guid>())) { //update general agency data Guid?SuccID = db_Ref.InsertUpdatetT_OE_ORGANIZATION(model.agency.ORG_IDX, null, null, null, null, null, model.agency.CLOUD, model.agency.API, true, UserIDX); //update database tags db_Ref.DeleteT_OE_ORGANIZATION_TAGS(model.agency.ORG_IDX, "Database"); foreach (string expertise in model.SelectedDatabase ?? new List <string>()) { db_Ref.InsertT_OE_ORGANIZATION_TAGS(model.agency.ORG_IDX, "Database", expertise); } //update app framework tags db_Ref.DeleteT_OE_ORGANIZATION_TAGS(model.agency.ORG_IDX, "App Framework"); foreach (string expertise in model.SelectedAppFramework ?? new List <string>()) { db_Ref.InsertT_OE_ORGANIZATION_TAGS(model.agency.ORG_IDX, "App Framework", expertise); } //award agency profile badge if (db_Accounts.UserCanEditOrgIDX(UserIDX, model.agency.ORG_IDX.ConvertOrDefault <Guid>())) { db_Forum.EarnBadgeController(UserIDX, "AgencyProfile"); } //now update the Azure search AzureSearch.PopulateSearchIndexOrganization(SuccID); if (SuccID != null) { TempData["Success"] = "Update successful."; } else { TempData["Error"] = "Error updating data."; } } return(RedirectToAction("Agency", new { selAgency = model.agency.ORG_IDX })); }
public ActionResult CreatePost(vmForumTopicView model) { int UserIDX = db_Accounts.GetUserIDX(); // ************************ VALIDATION ********************************************** // Check posting flood control if (!db_Forum.PassedPostFloodTest(UserIDX)) { TempData["Error"] = "Please wait at least 30 seconds between posts"; return(RedirectToAction("ShowTopic", new { slug = model.Topic.Slug })); } // Log user out if they are LockedOut but still authenticated T_OE_USERS u = db_Accounts.GetT_OE_USERSByIDX(UserIDX); if (u != null && u.LOCKOUT_ENABLED) { FormsAuthentication.SignOut(); return(RedirectToAction("Index", "Home")); } //required fields if (model.NewPostContent == null) { TempData["Error"] = "You must supply post content."; return(RedirectToAction("ShowTopic", new { slug = model.Topic.Slug })); } // ************************ END VALIDATION ********************************************** Guid?_postID = db_Forum.InsertUpdatePost(null, model.NewPostContent, null, null, false, false, false, null, null, model.Topic.Id, UserIDX, false); if (_postID != null) { //set topic last post date db_Forum.UpdateTopic_SetLastPostDate(model.Topic.Id, null); // Success send any notifications NotifyTopics(model.Topic.Id, UserIDX, "Post"); // 4. Update the users points score for posting db_Forum.InsertUpdateMembershipUserPoints(null, 1, System.DateTime.UtcNow, 0, _postID, null, UserIDX); // Update Azure search AzureSearch.PopulateSearchIndexForumPost(_postID); } // Return view return(RedirectToAction("ShowTopic", "Forum", new { slug = model.Topic.Slug })); }
public ActionResult SearchAdminPopulateIndex() { try { //***********PROJECTS ************************** //first reset all projects to unsynced db_EECIP.ResetT_OE_PROJECTS_Unsynced(); //then send all unsynced projects to Azure AzureSearch.PopulateSearchIndexProject(null); //***********AGENCIES ************************** //reset all agencies to unsynced db_Ref.ResetT_OE_ORGANIZATION_Unsynced(); //then send all unsynced agencies to Azure AzureSearch.PopulateSearchIndexOrganization(null); //***********ENT SERVICES ************************** db_EECIP.ResetT_OE_ORGANIZATION_ENT_SVCS_Unsynced(); //then send all unsynced agencies to Azure AzureSearch.PopulateSearchIndexEntServices(null); //***********PEOPLE ************************** db_Accounts.ResetT_OE_USERS_Unsynced(); //then send all unsynced agencies to Azure AzureSearch.PopulateSearchIndexUsers(null); //***********FORUM TOPICS ************************** db_Forum.UpdateTopic_SetAllUnsynced(); //then send all unsynced agencies to Azure AzureSearch.PopulateSearchIndexForumTopic(null); TempData["Success"] = "Search index populated."; } catch (Exception ex) { TempData["Error"] = ex.ToString().SubStringPlus(0, 100); } return(RedirectToAction("SearchAdmin", "Admin")); }
public ActionResult EditPost(vmForumTopicCreate model) { //get topic being edited Topic _topic = db_Forum.GetTopic_ByID(model.TopicId); if (_topic != null) { int UserIDX = db_Accounts.GetUserIDX(); // Update the Topic db_Forum.InsertUpdateTopic(model, UserIDX); Guid?newPostID = db_Forum.InsertUpdatePost(model.Id, model.Content, null, null, null, null, null, null, null, null, null, true); //3b. Set last update datetime db_Forum.UpdateTopic_SetLastPostDate(model.TopicId, null); // 5. Poll handling if (_topic.Poll_Id != null) { if (model.PollAnswers.Count(x => x != null) > 1) { // Update Poll Guid?PollID = db_Forum.InsertUpdatePoll(_topic.Poll_Id, model.IsPollClosed, System.DateTime.Now, model.PollCloseAfterDays, UserIDX); // Update poll answers foreach (PollAnswer answer in model.PollAnswers) { if (answer.Answer != null) { db_Forum.InsertUpdatePollAnswer(answer.Id, answer.Answer, PollID); } } } } // 7. Tag handling db_Forum.DeleteTopicTags(model.TopicId, "Topic Tag"); foreach (string feature in model.SelectedTags ?? new List <string>()) { db_Forum.InsertUpdateTopicTags(model.TopicId, "Topic Tag", feature); } // 11. Update Azure search AzureSearch.PopulateSearchIndexForumPost(newPostID); } return(RedirectToAction("ShowTopic", "Forum", new { slug = _topic.Slug })); }
public JsonResult SearchAdminSynonymDelete(int id) { int SuccID = db_Ref.DeleteT_OE_REF_SYNONYMS(id); if (SuccID == 0) { return(Json("Unable to delete record.")); } else { AzureSearch.UploadSynonyms(); AzureSearch.EnableSynonyms(); return(Json("Success")); } }
public JsonResult AgencyEntServiceDelete(int id) { int SuccID = db_EECIP.DeleteT_OE_ORGANIZATION_ENT_SVCS(id); if (SuccID == 0) { return(Json("Unable to delete record.")); } else { //now delete from Azure AzureSearch.DeleteSearchIndexEntService(id); return(Json("Success")); } }
public JsonResult UserDelete(int id) { int SuccID = db_Accounts.DeleteT_OE_USERS(id); AzureSearch.DeleteSearchIndexUsers(id); if (SuccID > 0) { //SUCCESS - now delete user from Azure search return(Json("Success")); } else { return(Json("User has been made inactive instead of being deleted due to data in the database.")); } }
public ActionResult DeletePost(Guid id) { int UserIDX = db_Accounts.GetUserIDX(); var post = db_Forum.GetPost_ByID(id); if (post != null) { //only allow delete if post by user or user is admin if (User.IsInRole("Admins") || UserIDX == post.MembershipUser_Id) { //if not topic starter, just delete post if (post.IsTopicStarter == false) { db_Forum.DeletePost(id); TempData["Success"] = "Post deleted"; return(RedirectToAction("ShowTopic", "Forum", new { id = post.Topic_Id })); } else { //remove post id from topic db_Forum.OrphanTopic(post.Topic_Id); //delete all posts for the topic List <Post> _postList = db_Forum.GetPost_ByTopicID(post.Topic_Id); foreach (Post p in _postList) { db_Forum.DeletePost(p.Id); } //then delete the topic int SuccID = db_Forum.DeleteTopic(post.Topic_Id); if (SuccID > 0) { //now sync with Azure AzureSearch.DeleteForumTopic(post.Topic_Id); TempData["Success"] = "Topic deleted"; } return(RedirectToAction("Index", "Forum")); } } } TempData["Error"] = "Unable to delete"; return(RedirectToAction("LatestTopics", "Forum", new { slug = post.Topic_Id })); }
public ActionResult SearchAdminDeleteIndex() { string err = ""; try { AzureSearch.DeleteSearchIndex(); TempData["Success"] = "Search index deleted."; } catch (Exception ex) { err = ex.ToString(); } TempData["Error"] = err; return(RedirectToAction("SearchAdmin", "Admin")); }
public ActionResult SearchAdminUploadSynonyms() { try { AzureSearch.UploadSynonyms(); AzureSearch.EnableSynonyms(); TempData["Success"] = "Synonyms uploaded and enabled."; } catch (Exception ex) { TempData["Error"] = ex.ToString().SubStringPlus(0, 100); } return(RedirectToAction("SearchAdmin", "Admin")); }
public JsonResult ProjectsDelete(IEnumerable <Guid> id) { int UserIDX = db_Accounts.GetUserIDX(); if (id == null || id.Count() == 0) { return(Json("No record selected to delete")); } else { foreach (var id1 in id) { //CHECK PERMISSIONS T_OE_PROJECTS p = db_EECIP.GetT_OE_PROJECTS_ByIDX(id1); if (p != null) { List <T_OE_ORGANIZATION> orgs = db_EECIP.GetT_OE_PROJECT_ORGS_ByProject(p.PROJECT_IDX); if (orgs != null) { if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgList(db_Accounts.GetUserIDX(), orgs)) { int SuccID = db_EECIP.DeleteT_OE_PROJECTS(id1); if (SuccID > 0) { //SUCCESS - now delete from Azure (need to concat proj and all proj orgs foreach (T_OE_ORGANIZATION _org in orgs) { AzureSearch.DeleteSearchIndexKey(id1.ToString() + "_" + _org.ORG_IDX.ToString()); } } else { return(Json("Unable to delete project.")); } } } } } //if got this far, success return(Json("Success")); } }
public JsonResult ProjectOrgDelete(string id, string id2) { if (id == null) { return(Json("No record selected to delete")); } else { Guid orgIDX = Guid.Parse(id); Guid projIDX = Guid.Parse(id2); List <T_OE_ORGANIZATION> allPO = db_EECIP.GetT_OE_PROJECT_ORGS_ByProject(projIDX); if (allPO != null) { //CHECK PERMISSIONS IF USER CAN EDIT PROJECT BASED ON ALL ORGS ASSOCIATED WITH PROJECT int UserIDX = db_Accounts.GetUserIDX(); if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgList(UserIDX, allPO)) { //FIND EXACT RECORD TO REMOVE T_OE_PROJECT_ORGS po = db_EECIP.GetT_OE_PROJECT_ORGS_ByProj_Org(orgIDX, projIDX); if (po != null) { int SuccID = db_EECIP.DeleteT_OE_PROJECT_ORGS(po.PROJECT_ORG_IDX); if (SuccID > 0) { //SUCCESS - now delete from Azure //now update the Azure search db_EECIP.InsertUpdatetT_OE_PROJECTS(projIDX, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, true, false); AzureSearch.DeleteSearchIndexKey(id2 + "_" + id); return(Json("Success")); } } } else { return(Json("You don't have rights to remove .")); } } } //if got this far, generic error return(Json("Unable to delete.")); }
public ActionResult RefAgencyEdit(T_OE_ORGANIZATION agency) { int UserIDX = db_Accounts.GetUserIDX(); Guid?SuccID = db_Ref.InsertUpdatetT_OE_ORGANIZATION(agency.ORG_IDX, agency.ORG_ABBR, agency.ORG_NAME, agency.STATE_CD, agency.EPA_REGION, agency.ORG_TYPE, null, null, true, UserIDX); if (SuccID != null) { AzureSearch.PopulateSearchIndexOrganization(SuccID); TempData["Success"] = "Update successful."; } else { TempData["Error"] = "Error updating data."; } //return View(model); return(RedirectToAction("RefAgencyEdit", new { id = SuccID })); }
public ActionResult SearchAdminSuggest(string term, bool fuzzy = true) { // Call suggest query and return results var response = AzureSearch.Suggest(term, fuzzy); List <string> suggestions = new List <string>(); foreach (var result in response.Results) { suggestions.Add(result.Text); } // Get unique items List <string> uniqueItems = suggestions.Distinct().ToList(); return(new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = uniqueItems }); }
private async Task ProductOptionsReceivedAsync(IDialogContext context, ProductQuery query) { var products = AzureSearch.CreateClient() .WithIndex(AzureSearch.Products) .Sort(nameof(Product.ListPrice), query.Sort) .Limit(query.Limit) .Find <Product>(query.ProductName); if (products.Any()) { PromptDialog.Choice(context, ProductSelectionReceivedAsync, products, "Add to basket:"); } else { await context.PostAsync("No products found."); await DisplayActionsCard(context); context.Wait(ActionSelectionReceivedAsync); } }
// GET: Dashboard/Search public ActionResult Search(string q, string facetDataType, string facetMedia, string facetRecordSource, string facetAgency, string facetState, string facetTags, string facetPopDensity, string facetRegion, string facetStatus, string activeTab, string currentPage, string sortType) { var model = new vmDashboardSearch(); model.q = q; model.facetDataType = facetDataType; model.facetMedia = facetMedia; model.facetRecordSource = facetRecordSource; model.facetAgency = facetAgency; model.facetState = facetState; model.facetTags = facetTags; model.facetPopDensity = facetPopDensity; model.facetRegion = facetRegion; model.facetStatus = facetStatus; model.activeTab = activeTab ?? "1"; model.currentPage = currentPage.ConvertOrDefault <int?>() ?? 1; model.sortType = sortType; model.searchResults = AzureSearch.QuerySearchIndex(model.q, model.facetDataType, model.facetMedia, model.facetRecordSource, model.facetAgency, model.facetState, model.facetTags, model.facetPopDensity, model.facetRegion, model.facetStatus, model.currentPage, model.sortType); return(View(model)); }
public ActionResult AgencyEntServiceEdit(vmDashboardAgency model) { if (ModelState.IsValid) { var z = model.edit_ent_services; int SuccID = db_EECIP.InsertUpdatetT_OE_ORGANIZATION_ENT_SVCS(z.ENT_PLATFORM_IDX, model.agency.ORG_IDX, z.ENT_PLATFORM_IDX, z.PROJECT_NAME, z.VENDOR, z.IMPLEMENT_STATUS, z.COMMENTS, z.PROJECT_CONTACT, z.ACTIVE_INTEREST_IND, false, db_Accounts.GetUserIDX(), true); if (SuccID > 0) { //sync to search service AzureSearch.PopulateSearchIndexEntServices(SuccID); TempData["Success"] = "Data Saved."; } else { TempData["Error"] = "Data Not Saved."; } } return(RedirectToAction("Agency", "Dashboard", new { selAgency = model.agency.ORG_IDX })); }
public ActionResult AddProjectOrg(vmDashboardAddProjectOrg model) { int UserIDX = db_Accounts.GetUserIDX(); if (model.selAgency != null) { List <T_OE_ORGANIZATION> projectOrgs = db_EECIP.GetT_OE_PROJECT_ORGS_ByProject(model.project.PROJECT_IDX); if (projectOrgs != null && projectOrgs.Count > 0) { //CHECK PERMISSIONS if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgList(UserIDX, projectOrgs)) { db_EECIP.InsertUpdateT_OE_PROJECT_ORGS(model.project.PROJECT_IDX, model.selAgency.ConvertOrDefault <Guid>(), UserIDX); //now update the Azure search db_EECIP.InsertUpdatetT_OE_PROJECTS(model.project.PROJECT_IDX, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, true, false); AzureSearch.PopulateSearchIndexProject(model.project.PROJECT_IDX); TempData["Success"] = "Update successful."; return(RedirectToAction("ProjectDetails", "Dashboard", new { id = model.project.PROJECT_IDX })); } else { TempData["Error"] = "You do not have rights to edit this project"; } } else { TempData["Error"] = "No project found"; } } else { TempData["Error"] = "Please select an agency"; } return(RedirectToAction("AddProjectOrg", "Dashboard", new { id = model.project.PROJECT_IDX })); }
public ActionResult Create(vmForumTopicCreate topicViewModel) { int UserIDX = db_Accounts.GetUserIDX(); // If viewModel is returned back to the view, repopulate view model fist topicViewModel.OptionalPermissions = GetOptionalPermissions(); topicViewModel.Categories = ddlForumHelpers.get_ddl_categories_tree(); topicViewModel.IsTopicStarter = true; topicViewModel.PollAnswers = topicViewModel.PollAnswers ?? new List <PollAnswer>(); topicViewModel.SelectedTags = topicViewModel.SelectedTags ?? new List <string>(); topicViewModel.AllTags = db_Forum.GetTopicTags_ByAttributeAll(Guid.NewGuid(), "Tags").Select(x => new SelectListItem { Value = x, Text = x }); /*---- End Re-populate ViewModel ----*/ if (ModelState.IsValid) { // ************************ VALIDATION ********************************************** // See if the user has actually added some content to the topic if (string.IsNullOrEmpty(topicViewModel.Content)) { if (topicViewModel.PollAnswers.Count > 0) { topicViewModel.Content = topicViewModel.Name; } else { TempData["Error"] = "You must supply content for the post."; return(RedirectToAction("Create")); } } // Check posting flood control if (!db_Forum.PassedTopicFloodTest(topicViewModel.Name, UserIDX)) { TempData["Error"] = "Can only post once per minute"; return(RedirectToAction("Create")); } // Log user out if they are LockedOut but still authenticated T_OE_USERS u = db_Accounts.GetT_OE_USERSByIDX(UserIDX); if (u != null && u.LOCKOUT_ENABLED) { FormsAuthentication.SignOut(); return(RedirectToAction("Index", "Home")); } // Check Permissions for topic opions if (!topicViewModel.OptionalPermissions.CanLockTopic) { topicViewModel.IsLocked = false; } // ************************ END VALIDATION ********************************************** // 1. Create the Topic Topic _Topic = db_Forum.InsertUpdateTopic(topicViewModel, UserIDX); if (_Topic != null) { // 2. Create Post and add to Topic Guid?_postID = db_Forum.InsertUpdatePost(null, topicViewModel.Content, null, null, true, null, null, null, null, _Topic.Id, UserIDX, false); if (_postID != null) { // 3. Reupdate the topic with post ID db_Forum.InsertUpdateTopic_withPost(_Topic.Id, _postID.ConvertOrDefault <Guid>()); //3b. Set last update datetime db_Forum.UpdateTopic_SetLastPostDate(_Topic.Id, null); // 4. Update the users points score for posting db_Forum.InsertUpdateMembershipUserPoints(null, 1, System.DateTime.UtcNow, 0, _postID, null, UserIDX); // 5. Poll handling if (topicViewModel.PollAnswers.Count(x => x != null) > 1) { // Create a new Poll Guid?PollID = db_Forum.InsertUpdatePoll(null, false, System.DateTime.Now, topicViewModel.PollCloseAfterDays, UserIDX); // Now sort the answers foreach (PollAnswer answer in topicViewModel.PollAnswers) { if (answer.Answer != null) { db_Forum.InsertUpdatePollAnswer(null, answer.Answer, PollID); } } // Add the poll to the topic db_Forum.SetTopicPollID(_Topic.Id, PollID.ConvertOrDefault <Guid>()); } // 6. File handling if (topicViewModel.Files != null && topicViewModel.Files.Any()) { UPloadPostFiles(topicViewModel.Files, UserIDX, _postID.ConvertOrDefault <Guid>()); } // 7. Tag handling db_Forum.DeleteTopicTags(_Topic.Id, "Topic Tag"); foreach (string feature in topicViewModel.SelectedTags ?? new List <string>()) { db_Forum.InsertUpdateTopicTags(_Topic.Id, "Topic Tag", feature); } // 8. Subscribe the user to the topic if they have checked the checkbox if (topicViewModel.SubscribeToTopic) { db_Forum.InsertUpdateTopicNotification(null, _Topic.Id, UserIDX); } // 9. Success so now send the emails //NotifyNewTopics(category, topic, unitOfWork); // 10. Badge Checking db_Forum.EarnBadgePostTopicEvent(UserIDX); // 11. Update Azure search AzureSearch.PopulateSearchIndexForumPost(_postID); // Redirect to the newly created topic return(RedirectToAction("ShowTopic", "Forum", new { slug = _Topic.Slug })); } } } if (TempData["Error"] == null) { TempData["Error"] = "Unable to save data"; } return(View(topicViewModel)); }
public ActionResult ProjectEdit(vmDashboardProjectDetails model) { int UserIDX = db_Accounts.GetUserIDX(); //CHECK PERMISSIONS if (User.IsInRole("Admins") || db_Accounts.UserCanEditOrgIDX(UserIDX, model.project.ORG_IDX.ConvertOrDefault <Guid>())) { //update project data Guid?newProjID = db_EECIP.InsertUpdatetT_OE_PROJECTS(model.project.PROJECT_IDX, model.project.ORG_IDX, model.project.PROJ_NAME ?? "", model.project.PROJ_DESC ?? "", model.project.MEDIA_TAG, model.project.START_YEAR ?? -1, model.project.PROJ_STATUS ?? "", model.project.DATE_LAST_UPDATE ?? -1, model.project.RECORD_SOURCE ?? "", model.project.PROJECT_URL ?? "", model.project.MOBILE_IND, model.project.MOBILE_DESC ?? "", model.project.ADV_MON_IND, model.project.ADV_MON_DESC ?? "", model.project.BP_MODERN_IND, model.project.BP_MODERN_DESC ?? "", model.project.COTS ?? "", model.project.VENDOR ?? "", model.project.PROJECT_CONTACT ?? "", model.project.PROJECT_CONTACT_IDX ?? -1, true, false, UserIDX, null, true); if (newProjID != null) { Guid newProjID2 = newProjID.ConvertOrDefault <Guid>(); //update program area tags db_EECIP.DeleteT_OE_PROJECT_TAGS(newProjID2, "Program Area"); foreach (string expertise in model.SelectedProgramAreas ?? new List <string>()) { db_EECIP.InsertT_OE_PROJECT_TAGS(newProjID2, "Program Area", expertise); } //update project url db_EECIP.DeleteT_OE_PROJECTS_URL(newProjID2); foreach (T_OE_PROJECT_URLS urls in model.sProjectUrlList ?? new List <T_OE_PROJECT_URLS>()) { db_EECIP.InsertT_OE_PROJECTS_URL(newProjID2, urls.PROJECT_URL, urls.PROJ_URL_DESC); } //update feature tags db_EECIP.DeleteT_OE_PROJECT_TAGS(newProjID2, "Project Feature"); foreach (string feature in model.SelectedFeatures ?? new List <string>()) { db_EECIP.InsertT_OE_PROJECT_TAGS(newProjID2, "Project Feature", feature); } //update files if (model.files != null) { foreach (HttpPostedFileBase file in model.files) { byte[] fileBytes = null; if (file != null) { using (Stream inputStream = file.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } fileBytes = memoryStream.ToArray(); //insert to database db_EECIP.InsertUpdateT_OE_DOCUMENTS(null, fileBytes, file.FileName, "project", file.ContentType, fileBytes.Length, model.FileDescription, null, newProjID2, null, UserIDX); } //award profile badge if (db_Accounts.UserCanEditOrgIDX(UserIDX, model.project.ORG_IDX.ConvertOrDefault <Guid>())) { db_Forum.EarnBadgeController(UserIDX, "ProjectDocument"); } } } } //award badges for new project if (newProjID2 != model.project.PROJECT_IDX)//new case { db_Forum.EarnBadgeAddProject(UserIDX); } //now update the Azure search AzureSearch.PopulateSearchIndexProject(newProjID2); TempData["Success"] = "Update successful."; return(RedirectToAction("ProjectDetails", "Dashboard", new { id = newProjID2, returnURL = model.ReturnURL })); } else { TempData["Error"] = "Error updating data."; } } else { TempData["Error"] = "You don't have permissions to edit this project."; } return(RedirectToAction(model.ReturnURL ?? "Projects", new { selAgency = model.project.ORG_IDX })); }
public ActionResult UserProfile(vmAccountUserProfile model) { //security validation (only allow site admin or user to edit their own profile) if ((!User.IsInRole("Admins")) && (model.UserIDX != db_Accounts.GetUserIDX())) { return(RedirectToAction("AccessDenied", "Home")); } if (ModelState.IsValid) { if (model.UserIDX > 0) { var strippedPhone = Regex.Replace(model.Phone ?? "", "[^0-9]", ""); if ((model.LinkedIn ?? "").Contains("www")) { try { Uri uri = new Uri(model.LinkedIn); model.LinkedIn = uri.Segments.Last(); } catch { } } int SuccID = db_Accounts.UpdateT_OE_USERS(model.UserIDX, null, null, model.FName, model.LName, model.Email, model.ActInd, null, null, null, strippedPhone, model.PhoneExt, null, null, model.OrgIDX, model.JobTitle, model.LinkedIn, model.NodeAdmin, model.ExcludeBadges); //update user expertise db_EECIP.DeleteT_OE_USER_EXPERTISE(model.UserIDX); foreach (string expertise in model.SelectedExpertise ?? new List <string>()) { db_EECIP.InsertT_OE_USER_EXPERTISE(model.UserIDX, expertise); } //award profile badge if (db_Accounts.GetUserIDX() == model.UserIDX) { db_Forum.EarnBadgeController(model.UserIDX, "UserProfile"); } ////avatar handling if (model.imageBrowes != null) { // ******************** VALIDATION START ******************************** //File too big check if (model.imageBrowes.ContentLength > 10485760) { TempData["Error"] = "File cannot exceed 10MB"; return(RedirectToAction("UserProfile", new { a = model.uListInd })); } //invalid file extension check var fileExtension = Path.GetExtension(model.imageBrowes.FileName); List <string> allowedExtensions = new List <string> { ".jpg", ".jpeg", ".png", ".bmp" }; if (!allowedExtensions.Contains(fileExtension)) { TempData["Error"] = "Invalid file type"; return(RedirectToAction("UserProfile", new { a = model.uListInd })); } // ******************** VALIDATION END ******************************** // Convert to Png var outputStream = model.imageBrowes.InputStream.ConvertImage(ImageFormat.Png); //save to db db_Accounts.UpdateT_OE_USERS_Avatar(model.UserIDX, Utils.ConvertGenericStreamToByteArray(outputStream)); //save to file system string fileName1 = model.UserIDX.ToString() + ".png"; model.imageBrowes.SaveAs(Server.MapPath("/Content/Images/Users/" + fileName1)); //award badge if (db_Accounts.GetUserIDX() == model.UserIDX) { db_Forum.EarnBadgeController(model.UserIDX, "Photogenic"); } } //update azure search AzureSearch.PopulateSearchIndexUsers(model.UserIDX); if (SuccID > 0) { TempData["Success"] = "Update successful."; } else { TempData["Error"] = "Error updating data."; } } } return(RedirectToAction("UserProfile", new { a = model.uListInd })); }
public ActionResult ImportData(vmAdminImportData model) { int UserIDX = db_Accounts.GetUserIDX(); //set dictionaries used to store stuff in memory Dictionary <string, int> colMapping = new Dictionary <string, int>(); //identifies the column number for each field to be imported //initialize variables bool headInd = true; bool anyError = false; //loop through each row foreach (string row in model.IMPORT_BLOCK.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)) { //split row's columns into string array string[] cols = row.Split(new char[] { '\t' }, StringSplitOptions.None); if (cols.Length > 0) //skip blank rows { if (headInd) { //********************************************************** //HEADER ROW - LOGIC TO DETERMINE WHAT IS IN EACH COLUMN //********************************************************** colMapping = Utils.GetColumnMapping("P", cols); headInd = false; model.projects = new List <ProjectImportType>(); } else { //********************************************************** //NOT HEADER ROW - READING IN VALUES //********************************************************** var colList = cols.Select((value, index) => new { value, index }); var colDataIndexed = (from f in colMapping join c in colList on f.Value equals c.index select new { _Name = f.Key, _Val = c.value }).ToList(); Dictionary <string, string> fieldValuesDict = new Dictionary <string, string>(); //identifies the column number for each field to be imported //loop through all values and insert to list foreach (var c in colDataIndexed) { fieldValuesDict.Add(c._Name, c._Val); } //VALIDATE ROW AND INSERT TO LOCAL OBJECT ProjectImportType p = db_EECIP.InsertOrUpdate_T_OE_PROJECT_local(UserIDX, fieldValuesDict); if (p.VALIDATE_CD == false) { anyError = true; } model.projects.Add(p); } } } //end each row //if no errors, just import. otherwise if (!anyError) { foreach (ProjectImportType ps in model.projects) { //import projects T_OE_PROJECTS x = ps.T_OE_PROJECT; Guid? ProjectIDX = db_EECIP.InsertUpdatetT_OE_PROJECTS(x.PROJECT_IDX, x.ORG_IDX, x.PROJ_NAME, x.PROJ_DESC, x.MEDIA_TAG, x.START_YEAR, x.PROJ_STATUS, x.DATE_LAST_UPDATE, x.RECORD_SOURCE, x.PROJECT_URL, x.MOBILE_IND, x.MOBILE_DESC, x.ADV_MON_IND, x.ADV_MON_DESC, x.BP_MODERN_IND, x.BP_MODERN_DESC, x.COTS, x.VENDOR, x.PROJECT_CONTACT, null, true, false, UserIDX, x.IMPORT_ID, true); //import features if (ps.FEATURES != null) { foreach (string f in ps.FEATURES.Split('|')) { if (f.Length > 0) { db_EECIP.InsertT_OE_PROJECT_TAGS(ProjectIDX.ConvertOrDefault <Guid>(), "Project Feature", f, UserIDX); } } } //import program areas if (ps.PROGRAM_AREAS != null) { foreach (string f in ps.PROGRAM_AREAS.Split('|')) { if (f.Length > 0) { db_EECIP.InsertT_OE_PROJECT_TAGS(ProjectIDX.ConvertOrDefault <Guid>(), "Program Area", f, UserIDX); } } } } //update azure search AzureSearch.PopulateSearchIndexProject(null); //clear form model.IMPORT_BLOCK = ""; model.projects = null; TempData["Success"] = "Data imported successfully"; } return(View(model)); }