public ActionResult UploadExcel(HttpPostedFileBase FileUpload, int?ImportType, FormCollection formCollection) { string test = String.Empty; #region Test GetAreaName ////Case 1 – If char 5 to 8 <> PROF, but upper 5 to 8 does = COUNS set field 8 to Counselor //test = GetAreaName("Adj Counslr-DSP&S-428A"); //Counselor ////Case 2 – If char 5 to 8 <> PROF, AND upper 5 to 8 does = LIBR set field 8 to Librarian //test = GetAreaName("Adj Librarian-Supplementl-014C"); //Librarian //test = GetAreaName("Adj Librarian FLC Supp 014C"); //Librarian ////Case 3 – If char 5 to 8 <> PROF, but upper 5 to 8 does = Nurses set field 8 to Nurses //test = GetAreaName("Adj Nurses-Unrestricted-015F"); //Nurses ////Case 4 – If char 5 to 8 <> PROF, but upper 5 to 8 does = "COORD" set field to Coord to end of string //test = GetAreaName("Adj Coord-Miscellaneous"); //Coord-Miscellaneous //test = GetAreaName("ADJ Coord-Work Experience"); //Coord-Work Experience ////Case 5 – Set to “Miscellaneous” WHERE Field 8 is still NULL and “misc” exists anywhere in the string //test = GetAreaName("Adj Prof-TS-SCC Miscellaneous"); //Miscellaneous //test = GetAreaName("Adj Prof-TS-CRC Miscellaneous"); //Miscellaneous //test = GetAreaName("Adj Prof- Miscellaneous Servic"); //Miscellaneous //test = GetAreaName("Adj Counslr-Misc Categorical"); //Counselor //test = GetAreaName("Adj Counselor-Miscellaneous"); //Counselor ////Case 6 – Set to “CJTC” WHERE Field 8 is still NULL and “CJTC” exists anywhere in the string //test = GetAreaName("Adjunct Professor CJTC"); //CJTC ////Case 7 – Has at least one dash AND there are two dashes (a dash found searching from the start and a dash found searching from the end are not in the same position //test = GetAreaName("Adj Prof-MAIN-Law"); //Law //test = GetAreaName("Adj Prof-MAIN-Eng & Ind Tech"); //Eng & Ind Tech //test = GetAreaName("Adj Prof-MCCL-Psychology"); //Psychology //test = GetAreaName("OL Prof-MAIN-Education"); //Education //test = GetAreaName("SUM Prof-DAVS-Fine & App Arts"); //Fine & App Arts //test = GetAreaName("Adj Prof-Miscellaneou"); //Miscellaneous ////Case 7b – Only one dash (a dash found searching from the start and a dash found searching from the end ARE in the same position). //test = GetAreaName("Adjunct Professors - Fire Tech"); //Fire Tech //test = GetAreaName("ADJ Coord-Work Experience"); //Coord-Work Experience //test = GetAreaName("Adj Instr Coord - Writing Cent"); //Writing Cent //test = GetAreaName("Adj Coord-Natomas 037B"); //Coord-Natomas 037B ////Case 8 - Get entire string when Field8 value is still NULL ////from Excel Full-Time page //test = GetAreaName("Professor-Mathematics"); //Mathematics //test = GetAreaName("English (Reading) Professor"); //English (Reading) Professor //test = GetAreaName("Professor-Humanities"); //Humanities //test = GetAreaName("Professor-Biology"); //Biology //test = GetAreaName("Professor-Physical Education"); //Physical Education #endregion #region Test GetDepartmentName ////Case 1 – If "COUNS" exists anywhere in the string, set field "DepartmentName" to "Counselor" //test = GetDepartmentName("Adj Counslr-DSP&S-428A"); //Counselor ////Case 3 –If dash exists, set field "DepartmentName" to text from dash to end of string (Existing) trim leading space. //test = GetDepartmentName("Adj Librarian-Supplementl-014C"); //Supplementl-014C ////If no 'prof', take first word //test = GetDepartmentName("Adj Librarian FLC Supp 014C"); //Librarian FLC Supp 014C ////Case 1.1 – If "NURSE" exists anywhere in string, set field "DepartmentName" to "Nurse". Note do not change "nursing" //test = GetDepartmentName("Adj Nurses-Unrestricted-015F"); //Nurses ////Case 2 – If "COORD" exists anywhere in the string, set field "DepartmentName" to text from "COORD" set field to Coord to end of string //test = GetDepartmentName("Adj Coord-Miscellaneous"); //Coord-Miscellaneous //test = GetDepartmentName("ADJ Coord-Work Experience"); //Coord-Work Experience ////If contain 'prof' ////If first four chars is not Prof, take whole field ////Case 3 –If dash exists, set field "DepartmentName" to text from dash to end of string (Existing) trim leading space. //test = GetDepartmentName("Adj Prof-TS-SCC Miscellaneous"); //TS-SCC Miscellaneous //test = GetDepartmentName("Adj Prof-TS-CRC Miscellaneous"); //TS-CRC Miscellaneous //test = GetDepartmentName("Adj Prof- Miscellaneous Servic"); //Miscellaneous Servic ////Case 1 – If "COUNS" exists anywhere in the string, set field "DepartmentName" to "Counselor" //test = GetDepartmentName("Adj Counslr-Misc Categorical"); //Counselor //test = GetDepartmentName("Adj Counselor-Miscellaneous"); //Counselor ////If first four chars is not Prof, take whole field //test = GetDepartmentName("Adjunct Professor CJTC"); //Adjunct Professor CJTC ////If contain 'prof' ////If first four chars is not Prof, take whole field ////Case 3 –If dash exists, set field "DepartmentName" to text from dash to end of string (Existing) trim leading space. //test = GetDepartmentName("Adj Prof-MAIN-Law"); //MAIN-Law //test = GetDepartmentName("Adj Prof-MAIN-Eng & Ind Tech"); //MAIN-Eng & Ind Tech //test = GetDepartmentName("Adj Prof-MCCL-Psychology"); //MCCL-Psychology //test = GetDepartmentName("OL Prof-MAIN-Education"); //MAIN-Education //test = GetDepartmentName("SUM Prof-DAVS-Fine & App Arts"); //DAVS-Fine & App Arts //test = GetDepartmentName("Adj Prof-Miscellaneous"); //Miscellaneous //test = GetDepartmentName("Adjunct Professors - Fire Tech"); //Fire Tech ////Case 2 – If "COORD" exists anywhere in the string, set field "DepartmentName" to text from "COORD" set field to Coord to end of string //test = GetDepartmentName("ADJ Coord-Work Experience"); //Coord-Work Experience //test = GetDepartmentName("Adj Instr Coord - Writing Cent"); //Coord - Writing Cent //test = GetDepartmentName("Adj Coord-Natomas 037B"); //Coord-Natomas 037B ////If contain 'prof' ////If first four chars is Prof.., begin take after first dash - //test = GetDepartmentName("Professor-Mathematics"); //Mathematics ////If contain 'prof' ////If first four chars is not Prof, take whole field //test = GetDepartmentName("English (Reading) Professor"); //English (Reading) Professor ////If contain 'prof' ////If first four chars is Prof.., begin take after first dash - //test = GetDepartmentName("Professor-Humanities"); //Humanities //test = GetDepartmentName("Professor-Biology"); //Biology //test = GetDepartmentName("Professor-Physical Education"); //Physical Education #endregion #region Test GetCampusDescr //test = GetCollegeCode("01ARCMAIN"); //test = GetCollegeCode("01SRPSTC"); //test = GetCollegeCode("02CRCMAIN"); //test = GetCollegeCode("04FLCMAIN"); //test = GetCollegeCode("04EDC"); //test = GetCollegeCode("05SCCMAIN"); //test = GetCollegeCode("03ETHAN"); //test = GetCollegeCode("03DO"); #endregion Error error = new Error(); List <string> errs = new List <string>(); if (FileUpload == null) { error.errCode = ErrorDetail.Failed; error.errMsg = ErrorDetail.GetMsg(error.errCode) + "!Please choose file to upload"; errs.Add(error.errMsg); TempData["ErrorList"] = errs; return(RedirectToAction("AdminImportCBU")); } string filename = FileUpload.FileName; var extension = filename.Split('.').Last().ToUpper(); if (extension != "XSL" && extension != "XLSX") { error.errCode = ErrorDetail.Failed; error.errMsg = ErrorDetail.GetMsg(error.errCode) + "!Only Excel file format is allowed (.xls or .xlsx)"; errs.Add(error.errMsg); TempData["ErrorList"] = errs; return(RedirectToAction("AdminImportCBU")); } if (ImportType == null) { error.errCode = ErrorDetail.Failed; error.errMsg = ErrorDetail.GetMsg(error.errCode) + "!Import type (Excel sheet) is not selected"; errs.Add(error.errMsg); TempData["ErrorList"] = errs; return(RedirectToAction("AdminImportCBU")); } bool result = Int32.TryParse(formCollection["Semesters"], out int semesterRecID); if (!result) { error.errCode = ErrorDetail.Failed; error.errMsg = ErrorDetail.GetMsg(error.errCode) + "!Please select semester"; errs.Add(error.errMsg); TempData["ErrorList"] = errs; return(RedirectToAction("AdminImportCBU")); } string filepath = "~/ImportExcel/1/"; if (!Directory.Exists(Server.MapPath(filepath))) { Directory.CreateDirectory(Server.MapPath(filepath)); } string targetpath = Server.MapPath(filepath); FileUpload.SaveAs(targetpath + filename); string pathToExcelFile = targetpath + filename; string sheetName = String.Empty; ExcelMembers excelMembers = new ExcelMembers(); ExcelSchedules excelSchedules = new ExcelSchedules(); //var uName = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserName(); var userId = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(); switch (ImportType) { case 1: errs = excelMembers.MembersImport(pathToExcelFile, "Full time", semesterRecID, userId); break; case 2: errs = excelMembers.MembersImport(pathToExcelFile, "Adjunct", semesterRecID, userId); break; case 3: errs = excelSchedules.ScheduleImport(pathToExcelFile, "REG-Schedule", semesterRecID, userId); break; case 4: errs = excelSchedules.ScheduleImport(pathToExcelFile, "ADJ-Schedule", semesterRecID, userId); break; default: return(RedirectToAction("AdminImportCBU" /*, new { fileTypeSelectResult = "Select appropriate file type" }*/)); } if (errs == null || errs.Count == 0) { return(RedirectToAction("Index", "Home")); } else { TempData["ErrorList"] = errs; return(RedirectToAction("AdminImportCBU")); } }
public async Task <ActionResult> Register(RegisterViewModel model, string Roles) { SelectList roles = new SelectList(db.AspNetRoles, "Id", "Name"); ViewBag.Roles = roles; var _users = db.AspNetUsers.ToList(); List <SelectListItem> _UsersRoles = new List <SelectListItem>(); foreach (var _user in _users) { var currentRoles = UserManager.GetRolesAsync(_user.Id); _UsersRoles.Add(new SelectListItem() { Text = _user.UserName, Value = currentRoles.Result.FirstOrDefault() }); } ViewBag.UsersAndRoles = _UsersRoles; ExcelMembers excelMembers = new ExcelMembers(); Error error = excelMembers.SplitFullName(model.UserLastFirstName, null, 0, out string lastName, out string firstName, out string middleName); if (error.errCode != ErrorDetail.Success) { ModelState.AddModelError("User Name Error", error.errMsg + ". Please enter last name and first name, separated by a comma."); return(View(model)); } if (ModelState.IsValid) { string selectedRole = roles.Where(t => t.Value == Roles).FirstOrDefault().Text; var user = new ApplicationUser { UserName = model.Email + ":" + selectedRole, Email = model.Email }; // placing selected Role Name to User Name in AspNetUsers table var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { using (LRCEntities context = new LRCEntities()) { try { AspNetUsers aUser = context.AspNetUsers.Where(s => s.Email.ToUpper() == model.Email.ToUpper()).FirstOrDefault(); aUser.LastFirstName = model.UserLastFirstName; context.SaveChanges(); } catch (DbEntityValidationException ex) { error.errCode = ErrorDetail.DataImportError; error.errMsg = ErrorDetail.GetMsg(error.errCode); foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors) { error.errMsg += ". Object: " + validationError.Entry.Entity.ToString(); foreach (DbValidationError err in validationError.ValidationErrors) { error.errMsg += ". " + err.ErrorMessage; } } } } if (error.errCode != ErrorDetail.Success) { ModelState.AddModelError("User Name Update Failed", error.errMsg); return(View(model)); } return(RedirectToAction("RegistrationRequestSentToAdmin", "Account")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }