public async Task <IActionResult> SignUp([Bind("Email,Password,ConfirmPassword")] registered_staff staff) { try { if (ModelState.IsValid) { if (_context.registered_staff.Any(info => info.Email == staff.Email)) { ModelState.AddModelError("Email", "The email address you entered is already in use"); ViewData["Message"] = "Already a member? Log In"; return(View(staff)); } else { _context.Add(staff); await _context.SaveChanges <registered_staff>(); //var type = new staff_type(staff.StaffID); _context.staff_type.Add(new staff_type(staff.StaffID)); await _context.SaveChanges <staff_type>(); return(View("RequiredInfo")); } } else { ViewData["Message"] = "Already a member? Log In"; return(View(staff)); } } catch (Exception e) { return(Error()); } }
public async Task <IActionResult> RequiredInfo([Bind("FirstName,MiddleInitial,LastName,Address,City,ZipCode,State,Phone,DateOfBirth,Gender, Image")] StaffRequiredInfo info) { if (info.Phone != null && info.Phone.Length < 10) { ModelState.AddModelError("Phone", "Invalid phone number."); } var validImageTypes = new string[] { "image/pjpeg", "image/jpeg", "image/tiff", "image/gif", "image/png", }; if (info.Image == null || info.Image.Length == 0) { return(View(info)); } if (!validImageTypes.Contains(info.Image.ContentType)) { ModelState.AddModelError("Image", "Please choose either a JPG, TIF, GIF or PNG image."); } if (info.DateOfBirth == null) { return(View(info)); } else { DateTime dt = Convert.ToDateTime(info.DateOfBirth); if (dt > DateTime.Today) { ModelState.AddModelError("DateOfBirth", "Date of birth must be before today's date "); } } if (ModelState.IsValid) { if (_context.registered_staff.Count() > 0) { try { registered_staff staff = _context.registered_staff.Last(); staff.FirstName = info.FirstName; staff.MiddleInitial = info.MiddleInitial; staff.LastName = info.LastName; staff.Address = info.Address; staff.City = info.City; staff.ZipCode = info.ZipCode; staff.State = info.State; staff.Phone = info.Phone; staff.DateOfBirth = info.DateOfBirth; staff.Gender = info.Gender; staff.ImageName = info.Image.FileName; var uploadDir = "uploads/images/" + staff.StaffID + "/"; var folderPath = Path.Combine(_hostingEnvironment.ContentRootPath, uploadDir); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var imagePath = Path.Combine(_hostingEnvironment.ContentRootPath, folderPath, info.Image.FileName); using (FileStream f = new FileStream(imagePath, FileMode.Create, FileAccess.ReadWrite)) { await info.Image.CopyToAsync(f); } await _context.SaveChanges <registered_staff>(); FillStaffTypes(); return(RedirectToAction("AdditionalInfo")); } catch (Exception e) { return(Error()); } } } return(View(info)); }
public async Task <IActionResult> AdditionalInfo([Bind("StaffType,OtherDescription,NativeLanguage,SecondLanguage,ThirdLanguage,TypeDL,Ethnicity,Height,Weight,HairColor,EyeColor,ShirtSize,PantSize,ChestSize,WaistSize,HipSize, DressSize,ShoeSize,Tattoos,Piercings,DesiredHourlyRate,DesiredWeeklyRate,SsnOrEin, BusinessName,Travel,Insurance, BankRouting, AccountNumber, Video, Resume")] StaffAdditionalInfo info) { if (info.SsnOrEin != null && info.SsnOrEin.Length < 9) { ModelState.AddModelError("SsnOrEin", "Invalid SSN."); } var validVideoTypes = new string[] { "video/avi", "video/msvideo", "video/x-msvideo", "video/x-flv", "video/x-ms-wmv", "video/mp4", "video/quicktime" }; var validResumeTypes = new string[] { "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain", "application/pdf", "application/rtf" }; if (info.Video != null) { if (!validVideoTypes.Contains(info.Video.ContentType)) { ModelState.AddModelError("Video", "Please choose either a AVI, FLV, WMV, MOV, or MP4 video."); } } if (info.Resume != null) { if (!validResumeTypes.Contains(info.Resume.ContentType)) { ModelState.AddModelError("Resume", "Please choose either a DOC, DOCX, TXT, PDF, or RTF document."); } } FillStaffTypes(); if (ModelState.IsValid) { if (_context.registered_staff.Count() > 0) { try { registered_staff staff = _context.registered_staff.Last(); staff_type type = _context.staff_type.Last(); if (info.StaffType != "Other") { staff.StaffType = info.StaffType; type.UpdateProperty(info.StaffType); } else { if (info.OtherDescription != null && info.OtherDescription != "") { staff.StaffType = info.OtherDescription; type.UpdateProperty(info.StaffType); type.UpdateProperty("Other_Description"); } else { staff.StaffType = info.StaffType; type.UpdateProperty(info.StaffType); } } staff.NativeLanguage = info.NativeLanguage; staff.SecondLanguage = info.SecondLanguage; staff.ThirdLanguage = info.ThirdLanguage; staff.TypeDL = info.TypeDL; staff.Ethnicity = info.Ethnicity; if (info.Height != null) { var h = info.Height.Split('\'')[0] + "." + info.Height.Split('\'')[1].Split('\"')[0]; staff.Height = Double.Parse(h); } else { staff.Height = 0.0; } if (info.Weight != null) { staff.Weight = Double.Parse(info.Weight); } else { staff.Weight = 0.0; } staff.HairColor = info.HairColor; staff.EyeColor = info.EyeColor; staff.ShirtSize = info.ShirtSize; staff.PantSize = info.PantSize; if (info.ChestSize != null) { staff.ChestSize = Double.Parse(info.ChestSize); } else { staff.ChestSize = 0.0; } if (info.WaistSize != null) { staff.WaistSize = Double.Parse(info.WaistSize); } else { staff.WaistSize = 0.0; } if (info.HipSize != null) { staff.HipSize = Double.Parse(info.HipSize); } else { staff.HipSize = 0.0; } staff.NickName = info.NickName; staff.DressSize = info.DressSize; staff.ShoeSize = info.ShoeSize; staff.Tattoos = info.Tattoos; staff.Piercings = info.Piercings; staff.DesiredHourlyRate = info.DesiredHourlyRate; staff.DesiredWeeklyRate = info.DesiredWeeklyRate; staff.SsnOrEin = info.SsnOrEin; staff.BusinessName = info.BusinessName; staff.Travel = info.Travel; staff.Insurance = info.Insurance; staff.BankRouting = info.BankRouting; staff.AccountNumber = info.AccountNumber; if (info.Resume != null) { staff.Resume = info.Resume.FileName; var uploadDir = "uploads/resumes/" + staff.StaffID + "/"; var folderPath = Path.Combine(_hostingEnvironment.ContentRootPath, uploadDir); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var resumePath = Path.Combine(_hostingEnvironment.ContentRootPath, folderPath, info.Resume.FileName); using (FileStream f = new FileStream(resumePath, FileMode.Create, FileAccess.ReadWrite)) { await info.Resume.CopyToAsync(f); } } if (info.Video != null) { staff.VideoName = info.Video.FileName; var uploadDir = "uploads/videos/" + staff.StaffID + "/"; var folderPath = Path.Combine(_hostingEnvironment.ContentRootPath, uploadDir); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var videoPath = Path.Combine(_hostingEnvironment.ContentRootPath, folderPath, info.Video.FileName); using (FileStream f = new FileStream(videoPath, FileMode.Create, FileAccess.ReadWrite)) { await info.Video.CopyToAsync(f); } } await _context.SaveChanges <registered_staff>(); await _context.SaveChanges <staff_type>(); ViewBag.ConfirmationMessage = "Your account has been created!"; ViewData["staffID"] = "Staff ID: " + staff.StaffID; return(View("AccountCreated")); } catch (Exception e) { return(Error()); } } } return(View(info)); }