public ActionResult Details(string id) { CampaignViewModel campaignVM = new CampaignViewModel(); CampaignDTO campaign = campaignVM.GetCampaignById(id); return(View(campaign)); }
public ActionResult Edit(string id) { CampaignViewModel campaignVM = new CampaignViewModel(); CampaignDTO status = campaignVM.GetCampaignById(id); status.CampaignID = id; return(View(status)); }
public ActionResult Create(CandidateDTO paramCandidateDTO, HttpPostedFileBase CandidateImage) { if (paramCandidateDTO == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // get the campaign ID by camparing the name from the list which was selected var CampId = ""; CandidateDTO candidateDTO = new CandidateDTO(); CampaignViewModel camVM = new CampaignViewModel(); // get all the campaigns in the list with thier ids var camp = candidateDTO.Campaigns; camp = camVM.GetAllCampaignNamesAndID(); foreach (var item in camp) { if (item.Description == paramCandidateDTO.CampaignID) { CampId = item.CampaignID; } } //var Name = paramCandidateDTO.UserPic; var UserName = paramCandidateDTO.FirstName.Trim(); var Surname = paramCandidateDTO.Surname.Trim(); var Gender = paramCandidateDTO.Gender; var Country = paramCandidateDTO.Country.Trim(); var City = paramCandidateDTO.City.Trim(); var DOB = paramCandidateDTO.DOB.Trim(); var CampaignID = CampId; // get the country of the from Campaign table, check the country matches the candidate country // enter the details to the database else redirect the user to an message Page. var CampCountry = ""; CampaignViewModel cmVM = new CampaignViewModel(); CampaignDTO cmDTO = new CampaignDTO(); cmDTO = cmVM.GetCampaignById(CampaignID); CampCountry = cmDTO.Country; CampCountry = CampCountry.Trim(); if (Country != CampCountry) { return(View("Error")); } else { // no check if the same candidate is already registerd in the same campaing twice try { //byte CandidatePic = paramCandidateDTO.CandidatePic; if (CandidateImage != null) { // To convert the user uploaded Photo as Byte Array before save to DB paramCandidateDTO.CandidatePic = new byte[CandidateImage.ContentLength]; CandidateImage.InputStream.Read(paramCandidateDTO.CandidatePic, 0, CandidateImage.ContentLength); } using (sqlconn) { using (SqlCommand cmd = new SqlCommand("InsertIntoCandidatesTable", sqlconn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", UserName); cmd.Parameters.AddWithValue("@Surname", Surname); cmd.Parameters.AddWithValue("@Gender", Gender); cmd.Parameters.AddWithValue("@Country", Country); cmd.Parameters.AddWithValue("@City", City); cmd.Parameters.AddWithValue("@DOB", DOB); cmd.Parameters.AddWithValue("@CandidatePic", paramCandidateDTO.CandidatePic); cmd.Parameters.AddWithValue("@CampaignID", CampaignID); sqlconn.Open(); cmd.ExecuteNonQuery(); sqlconn.Close(); } } //roleManager.Create(new IdentityRole(UserName)); //return Redirect("~/Candidate/AddCandidate"); return(Redirect("~/Candidate/Create")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Error: " + ex); return(View("Create")); } } }