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 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 { } } //logic for properly blanking out OrgIDX (only when accessed via Admin screen) if (model.OrgIDX == null && model.uListInd == "a") { model.OrgIDX = Guid.Empty; } 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, null, null, null); //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).ToUpper(); 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 if (model.ActInd) { AzureSearch.PopulateSearchIndexUsers(model.UserIDX); } else { AzureSearch.DeleteSearchIndexUsers(model.UserIDX); } //update contact in MailChimp MailChimpHelper _mailchimp = new MailChimpHelper(); if (model.ActInd) { _mailchimp.AddUpdateMailChimpContact(model.Email, model.FName, model.LName); } else { _mailchimp.RemoveMailChimpContant(model.Email); } if (SuccID > 0) { TempData["Success"] = "Update successful."; } else { TempData["Error"] = "Error updating data."; } } } return(RedirectToAction("UserProfile", new { a = model.uListInd })); }