public ActionResult DeleteConfirmed(int id) { CandidatePersonalInfProfile CandidatePersonalInfProfile = db.CandidatePersonalInfProfile.Find(id); db.CandidatePersonalInfProfile.Remove(CandidatePersonalInfProfile); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: CandidatePersonalInfProfile/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CandidatePersonalInfProfile CandidatePersonalInfProfile = db.CandidatePersonalInfProfile.Find(id); if (CandidatePersonalInfProfile == null) { return(HttpNotFound()); } return(View(CandidatePersonalInfProfile)); }
public ActionResult Save([Bind(Include = "imgurl")] CandidatePersonalInfProfile CandidatePersonalInfProfile, string t, string l, string h, string w, string fileName) { try { // Calculate dimensions var top = Convert.ToInt32(t.Replace("-", "").Replace("px", "")); var left = Convert.ToInt32(l.Replace("-", "").Replace("px", "")); var height = Convert.ToInt32(h.Replace("-", "").Replace("px", "")); var width = Convert.ToInt32(w.Replace("-", "").Replace("px", "")); // Get file from temporary folder var fn = Path.Combine(Server.MapPath(MapTempFolder), Path.GetFileName(fileName)); // ...get image and resize it, ... var img = new WebImage(fn); img.Resize(width, height); // ... crop the part the user selected, ... img.Crop(top, left, img.Height - top - AvatarStoredHeight, img.Width - left - AvatarStoredWidth); // ... delete the temporary file,... System.IO.File.Delete(fn); // ... and save the new one. var newFileName = "~/Avatars\\" + User.Identity.GetUserId().ToString() + Path.GetExtension(fileName).ToString(); var newFileLocation = HttpContext.Server.MapPath(newFileName); if (Directory.Exists(Path.GetDirectoryName(newFileLocation)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(newFileLocation)); } String Userd = User.Identity.GetUserId().ToString(); img.Save(newFileLocation); int ID = Convert.ToInt16(db.CandidatePersonalInfProfile.Where(x => x.UserID == Userd).SingleOrDefault().ID); CandidatePersonalInfProfile = db.CandidatePersonalInfProfile.Find(ID); CandidatePersonalInfProfile.imgurl = User.Identity.GetUserId().ToString() + Path.GetExtension(fileName).ToString(); db.Entry(CandidatePersonalInfProfile).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, avatarFileLocation = newFileName })); } catch (Exception ex) { return(Json(new { success = false, errorMessage = "Unable to upload file.\nERRORINFO: " + ex.Message })); } }
public ActionResult Edit([Bind(Include = "ID,UserID,Name,Surname,RSACitizen,CandidateIDNumber,Race,Gender,Disability,CellphoneNumber,TelephoneNumber,EmailAddress,StreetAddress,DriversLicense,TownID")] CandidatePersonalInfProfile CandidatePersonalInfProfile) { String TW = Convert.ToString(db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().Town.ToString()); String PR = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().ProvinceName.ToString(); String RG = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().Region.ToString(); int TWI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().TownID; int?PRI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().ProvinceID; int RGI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().RegionID; ViewBag.InTown = (TW); ViewBag.InProvince = PR; ViewBag.InRegion = RG; ViewBag.InTownI = TWI; ViewBag.InProvinceI = PRI; ViewBag.InRegionI = RGI; List <SelectListItem> listitem = new List <SelectListItem>(); List <SelectListItem> listitemdrop = new List <SelectListItem>(); DropdownListValues dropSa = new DropdownListValues(); ViewBag.Raceset = new SelectList(db.ListRace, "RaceID", "Race"); ViewBag.Genderset = new SelectList(db.Gender, "GenderID", "Gender1"); ViewBag.Disabilityset = new SelectList(db.ListDisability, "DisabilityID", "Disability"); ViewBag.Provinces = new SelectList(db.Province, "ProvinceID", "ProvinceName", PRI); ViewBag.Region = new SelectList(db.Region.Where(x => x.ProvinceID == PRI), "RegionID", "Region1", RGI); ViewBag.Town = new SelectList(db.Town.Where(x => x.RegionID == RGI), "TownID", "Town1", TWI); DropdownListValues dropdrivers = new DropdownListValues(); //dropdrivers.id = 0; //dropdrivers.Values = "Do you have a drivers license?"; //listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 1; dropdrivers.Values = "Yes"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 2; dropdrivers.Values = "No"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); ViewBag.dropdrivers = new SelectList(listitemdrop, "Text", "Value"); //dropSa.id = 0; //dropSa.Values = "Are you a South African Citizen"; //listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 1; dropSa.Values = "Yes"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 2; dropSa.Values = "No"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); ViewBag.Dropdownlist = new SelectList(listitem, "Text", "Value"); CandidatePersonalInfProfile.UserID = User.Identity.GetUserId(); CandidatePersonalInfProfile.UpdatedDate = System.DateTime.Today; if (ModelState.IsValid) { db.Entry(CandidatePersonalInfProfile).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(CandidatePersonalInfProfile)); }
public ActionResult Edit(int?id) { if (id == null || id < 1) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CandidatePersonalInfProfile CandidatePersonalInfProfile = db.CandidatePersonalInfProfile.Find(id); if (CandidatePersonalInfProfile == null) { return(HttpNotFound()); } if (CandidatePersonalInfProfile.UserID == User.Identity.GetUserId()) { String TW = Convert.ToString(db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().Town.ToString()); String PR = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().ProvinceName.ToString(); String RG = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().Region.ToString(); int TWI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().TownID; int?PRI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().ProvinceID; int RGI = db.LocationView.Where(x => x.TownID == CandidatePersonalInfProfile.TownID).SingleOrDefault().RegionID; ViewBag.InTown = (TW); ViewBag.InProvince = PR; ViewBag.InRegion = RG; ViewBag.InTownI = TWI; ViewBag.InProvinceI = PRI; ViewBag.InRegionI = RGI; List <SelectListItem> listitem = new List <SelectListItem>(); List <SelectListItem> listitemdrop = new List <SelectListItem>(); DropdownListValues dropSa = new DropdownListValues(); ViewBag.Raceset = new SelectList(db.ListRace, "RaceID", "Race"); ViewBag.Genderset = new SelectList(db.Gender, "GenderID", "Gender1"); ViewBag.Disabilityset = new SelectList(db.ListDisability, "DisabilityID", "Disability"); ViewBag.Provinces = new SelectList(db.Province, "ProvinceID", "ProvinceName", PRI); ViewBag.Region = new SelectList(db.Region.Where(x => x.ProvinceID == PRI), "RegionID", "Region1", RGI); ViewBag.Town = new SelectList(db.Town.Where(x => x.RegionID == RGI), "TownID", "Town1", TWI); DropdownListValues dropdrivers = new DropdownListValues(); //dropdrivers.id = 0; //dropdrivers.Values = "Do you have a drivers license?"; //listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 1; dropdrivers.Values = "Yes"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 2; dropdrivers.Values = "No"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); ViewBag.dropdrivers = new SelectList(listitemdrop, "Text", "Value"); //dropSa.id = 0; //dropSa.Values = "Are you a South African Citizen"; //listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 1; dropSa.Values = "Yes"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 2; dropSa.Values = "No"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); ViewBag.Dropdownlist = new SelectList(listitem, "Text", "Value"); return(View(CandidatePersonalInfProfile)); } else { FormsAuthentication.SignOut(); Roles.DeleteCookie(); Session.Clear(); return(RedirectToAction("Login", "Account")); } }
public ActionResult Create([Bind(Include = "ID,UserID,Name,Surname,RSACitizen,CandidateIDNumber,Race,Gender,Disability,TownID,CellphoneNumber,TelephoneNumber,StreetAddress,DriversLicense")] CandidatePersonalInfProfile CandidatePersonalInfProfile) { DropdownListValues dropdrivers = new DropdownListValues(); List <SelectListItem> listitem = new List <SelectListItem>(); List <SelectListItem> listitemdrop = new List <SelectListItem>(); DropdownListValues dropSa = new DropdownListValues(); String UserID = User.Identity.GetUserId(); CandidatePersonalInfProfile.EmailAddress = User.Identity.GetUserName(); CandidatePersonalInfProfile.UserID = UserID; CandidatePersonalInfProfile.UpdatedDate = System.DateTime.Today; if (ModelState.IsValid == false) { if (db.CandidatePersonalInfProfile.Any(p => p.UserID == UserID)) { var Ident = db.CandidatePersonalInfProfile.Where(x => x.UserID == UserID).Select(x => x.ID).ToList(); return(RedirectToAction("Index", "CandidatePersonalInfProfile", new { id = Ident })); } } else { db.CandidatePersonalInfProfile.Add(CandidatePersonalInfProfile); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Race = new SelectList(db.ListRace, "RaceID", "Race"); ViewBag.Gender = new SelectList(db.Gender, "GenderID", "Gender1"); ViewBag.Disability = new SelectList(db.ListDisability, "DisabilityID", "Disability"); ViewBag.Provinces = new SelectList(db.Province, "ProvinceID", "ProvinceName"); ViewBag.Region = new SelectList(db.Region, "RegionID", "Region1"); ViewBag.Town = new SelectList(db.Town, "TownID", "Town1"); dropdrivers.id = 0; dropdrivers.Values = "Do you have a drivers license?"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 1; dropdrivers.Values = "Yes"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); dropdrivers.id = 2; dropdrivers.Values = "No"; listitemdrop.Add(new SelectListItem() { Value = dropdrivers.Values, Text = dropdrivers.id.ToString() }); ViewBag.dropdrivers = new SelectList(listitemdrop, "Text", "Value"); dropSa.id = 0; dropSa.Values = "Are you a South African Citizen"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 1; dropSa.Values = "Yes"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); dropSa.id = 2; dropSa.Values = "No"; listitem.Add(new SelectListItem() { Value = dropSa.Values, Text = dropSa.id.ToString() }); ViewBag.Dropdownlist = new SelectList(listitem, "Text", "Value"); return(View(CandidatePersonalInfProfile)); }