// GET: Candidate public ActionResult RegisterCandidate(string StaffGUID, string id) { ViewBag.message = TempData["message"]; ViewBag.success = TempData["success"]; if (StaffGUID != null) { StaffGUIDControl staffGUID = new StaffGUIDControl(); if (staffGUID.IsLogedIn(db, StaffGUID)) { staffGUID.RefreshGUID(db); CandidateVM candidateVM = new CandidateVM(); candidateVM.StaffView = staffGUID; ViewBag.PartyID = new SelectList(db.Parties, "PartyID", "PartyName"); ViewBag.ProvinceID = new SelectList(db.Provinces, "ProvinceID", "ProvinceName"); ViewBag.CandidatePosition_ID = new SelectList(db.CandidatePositions, "CandidatePosition_ID", "CandidatePosition_Description"); return View(candidateVM); } else { TempData["message"] = "Your Session Has Expired! Please Login Again!"; return RedirectToAction("StaffLogin", "Staff"); } } else { TempData["message"] = "Your Session Has Expired! Please Login Again!"; return RedirectToAction("StaffLogin", "Staff"); } }
/// <summary> /// Runs the select candidate by candidate ID stored procedure /// </summary> /// <param name="condidateID"></param> /// <returns></returns> public CandidateVM SelectCandidateByCandidateID(int condidateID) { CandidateVM candidate = new CandidateVM(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_candidate_by_candidate_id", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CandidateID", condidateID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.Read()) { candidate.CandidateID = reader.GetInt32(0); candidate.PersonID = reader.GetInt32(1); candidate.ElectionID = reader.GetInt32(2); candidate.Votes = reader.GetInt32(3); candidate.Active = reader.GetBoolean(4); candidate.FirstName = reader.GetString(5); candidate.LastName = reader.GetString(6); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(candidate); }
public ActionResult EditCandidate(CandidateVM model) { if (!ModelState.IsValid) { return(View("EditCandidate", model)); } var candidate = db.VoteUsers.Where(x => x.VoterId == model.VoterId).FirstOrDefault(); if (candidate == null) { return(RedirectToAction("Index")); } candidate.FirstName = model.FirstName; candidate.LastName = model.LastName; candidate.Email = model.Email; candidate.Phone = model.Phone; candidate.ImageString = model.ImageString; db.SaveChanges(); TempData["SM"] = "Changes Saved"; return(RedirectToAction("edit-candidate", new { Id = model.VoterId })); }
public ResultVM CreateCandidate(CandidateVM model) { Result.Success = false; // generate userId string newVoterId = GenerateUserId(); var candidate = new VoteUserDTO { UserId = model.UserId, VoterId = newVoterId, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Phone = model.Phone, PositionId = model.PositionId, ImageString = model.ImageString, DateAddedUtc = DateTime.UtcNow }; _db.VoteUsers.Add(candidate); _db.SaveChanges(); // add user to role AddToRole(candidate.UserId, "Candidate"); //this.AddToRole(candidate.UserId, "Candidate"); Result.Success = true; return(Result); }
public async Task <IActionResult> Create(CandidateVM candidate) { if (ModelState.IsValid) { try { var imageTitle = _candidateRepository.AddImage(candidate.Image, _webHostEnvironment); var fileName = await _candidateRepository.AddResumeAsync(candidate.Resume, _webHostEnvironment); var newCandidate = new Candidate() { FullName = candidate.FullName, JobTitle = candidate.JobTitle, Age = candidate.Age, City = candidate.City, Area = candidate.Area, Address = candidate.Address, ImageTitle = imageTitle, FileName = fileName }; await _candidateRepository.AddAsync(newCandidate); await _candidateRepository.SaveAllAsync(); return(View("Details", newCandidate)); } catch (Exception) { return(View()); } } return(View()); }
public ActionResult CreateCandidate(string voterId, int positionId) { CandidateVM model; if (string.IsNullOrEmpty(voterId)) { model = new CandidateVM() { PositionId = positionId }; } else { model = db.VoteUsers.Where(x => x.VoterId == voterId).Select(x => new CandidateVM() { VoterId = x.VoterId, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, PositionId = positionId }).FirstOrDefault(); } ViewBag.Postion = positionId; ViewBag.PositionName = db.Position.Where(x => x.Id == positionId).Select(x => x.Name).FirstOrDefault(); return(View("CreateCandidate", model)); }
public JsonResult GetDetails(int id) { Candidate Candidate = db.Candidate.Find(id); if (Candidate == null) { return(Json(new { Status = 0, Message = "Not found" })); } CandidateVM vm = mapper.Map <CandidateVM>(Candidate); return(Json(new { Status = 1, Message = "Ok", Content = RenderPartialViewToString("Details", vm) })); }
public ActionResult EditCandidate(string Id) { var candidate = db.VoteUsers.Where(x => x.VoterId == Id).FirstOrDefault(); if (candidate == null) { return(RedirectToAction("Index")); } var model = new CandidateVM(candidate); return(View("EditCandidate", model)); }
//[Authorize(Roles = "Admin, Employer")] public async Task <IActionResult> Index() { CandidateVM candidateVM = new CandidateVM(); AppUser user = await _userManager.FindByNameAsync(User.Identity.Name); candidateVM.Applies = _context.Applies.Where(x => x.AppUserId == user.Id).Include(x => x.City).ToList(); candidateVM.Jobs = _context.Jobs.Where(x => x.AppUserId == user.Id) .Include(x => x.Category) .Include(x => x.City) .Include(x => x.Country) .Include(x => x.AppUser) .ToList(); return(View(candidateVM)); }
public ActionResult DeleteCandidate(CandidateVM candidate) { try { candidate = _candidateManager.RetrieveCandidateByCandidateID(candidate.CandidateID); _candidateManager.DeleteCandidate(candidate.CandidateID); return(RedirectToAction("Details", new { id = candidate.ElectionID })); } catch (Exception) { return(View()); } }
public ActionResult CreateCandidate(CandidateVM model) { if (!ModelState.IsValid) { return(View("CreateCandidate", model)); } Result = User.CreateCandidate(model); if (!Result.Success) { ModelState.AddModelError("duplicate", Result.ErrorMessage); return(View("CreateCandidate", model)); } TempData["SM"] = "Candidate added successfully"; return(RedirectToAction("create-candidate", new { positionId = model.PositionId })); }
public IEnumerable <CandidateVM> GetCandidatesFor(int positionId) { // init candidate vm var result = new List <CandidateVM>(); var allUsers = _db.VoteUsers.Where(x => x.PositionId == positionId).ToList(); foreach (var user in allUsers) { if (UserManager.IsInRoleAsync(user.UserId, "Candidate").Result) { var candidate = new CandidateVM(user); result.Add(candidate); } } //return result return(result); }
public static Candidate CandidateVMToCandidate(CandidateVM candidateVM, IDataRepository dataRepository) { var candidate = new Candidate() { Age = candidateVM.Age, Email = candidateVM.Email, Experience = candidateVM.Experience, FullName = candidateVM.FullName, GenderId = candidateVM.GenderId, JobStateId = candidateVM.JobStateId, Phone = candidateVM.Phone, Position = candidateVM.Position, ProjectId = candidateVM.ProjectId, TechStackId = candidateVM.TechStackId, ResidentAddress = candidateVM.ResidentAddress, // candidate.ResumePath -- The value is set in controller }; return(candidate); }
/// <summary> /// runs the select candidates by active stored procedure /// </summary> /// <param name="active"></param> /// <returns></returns> public List <CandidateVM> SelectCandidatesByActive(bool active) { List <CandidateVM> candidates = new List <CandidateVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_candidates_by_active", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@active", active); try { var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var candidate = new CandidateVM(); candidate.CandidateID = reader.GetInt32(0); candidate.PersonID = reader.GetInt32(1); candidate.ElectionID = reader.GetInt32(2); candidate.Votes = reader.GetInt32(3); candidate.Active = reader.GetBoolean(4); candidate.FirstName = reader.GetString(5); candidate.LastName = reader.GetString(6); candidates.Add(candidate); } } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(candidates); }
public ActionResult Create(CandidateVM CVM, HttpPostedFileBase file) { if (!ModelState.IsValid || file == null || file.ContentLength == 0) { RedirectToAction("Create"); } Candidate CandidateDomain = new Candidate() { CandidateId = CVM.CandidateId, FirstName = CVM.FirstName, LastName = CVM.LastName, Gender = (Gender)CVM.Gender, DateOfBirthday = CVM.DateOfBirthday, Email = CVM.Email, Address = CVM.Address, PhoneNumber = CVM.PhoneNumber, ImageUrl = file.FileName, bio = CVM.bio }; candidateService.Add(CandidateDomain); candidateService.Commit(); // candidateService.Dispose(); var fileName = ""; if (file.ContentLength > 0) { fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Uploads/"), fileName); file.SaveAs(path); } return(RedirectToAction("Index")); }
public IActionResult Create() { var model = new CandidateVM(); return(View(model)); }
public async Task <IActionResult> CreateCandidate([FromBody] CandidateVM model) { var result = await _candidateManager.AddAsync(new Candidate { Name = model.Name }); return(new ContentActionResult <Candidate>((result == null) ? HttpStatusCode.BadRequest : HttpStatusCode.Created, result, (result == null) ? "BadRequest" : "Created", Request)); }
// PUT: api/Candidate/5 public Response Put([FromBody] CandidateVM candidate) { return(_repository.Save(candidate)); }
public async Task <ActionResult> MakeNewCandidate(int userId, int positionId) { if (userId == null || positionId == null) { return(Json(new { Status = 0, Message = "Invalid attempt" })); } // get brief user info var user = db.Users.Where(x => x.Id == userId).FirstOrDefault(); string userImage = db.Images.Where(x => x.UserId == user.Id).Select(x => x.Image1).FirstOrDefault(); // remove user from voter role if (await User.IsInRole(user.Id, "Voter")) { // get existing voter user var voteUser = db.VoteUsers.Where(x => x.UserId == user.Id).FirstOrDefault(); // update user image in voteusers table voteUser.PositionId = positionId; voteUser.ImageString = userImage; // save db db.SaveChanges(); // remove user from voter role User.RemoveFromRole(user.Id, "Voter"); User.AddToRole(user.Id, "Candidate"); // return success Json return(Json(new { Status = 1, Message = "Created Candidate Successfully" })); } // create new vote User profile var newVoteUser = new CandidateVM() { UserId = user.Id, FirstName = user.FirstName, LastName = user.LastName + " " + user.OtherNames, Phone = user.PhoneNumber, Email = user.Email, PositionId = positionId, ImageString = userImage }; // add new profile //db.VoteUsers.Add(newVoteUser); // Result = User.CreateCandidate(newVoteUser); //db.SaveChanges(); // return Json status if (Result.Success) { return(Json(new { Status = 1, Message = "Created Candidate Successfully" })); } else { return(Json(new { Status = 0, Message = "Error: Unable to create Candidate" })); } }