Example #1
0
        private void AssertCandidate(CandidateModel model, EmployerMemberView view)
        {
            Assert.AreEqual(view.Id, model.Id);
            Assert.AreEqual(view.GetCandidateTitle(), model.FullName);
            Assert.AreEqual(view.Status, model.Status);
            Assert.AreEqual(_memberStatusQuery.GetLastUpdatedTime(view, view, view.Resume).ToUniversalTime(), model.LastUpdatedTime);
            Assert.AreEqual(view.Address.Location.ToString(), model.Location);

            var salary = view.DesiredSalary == null ? null : view.DesiredSalary.ToRate(SalaryRate.Year);

            Assert.AreEqual(salary == null ? null : salary.LowerBound, model.DesiredSalary == null ? null : model.DesiredSalary.LowerBound);
            Assert.AreEqual(salary == null ? null : salary.UpperBound, model.DesiredSalary == null ? null : model.DesiredSalary.UpperBound);

            Assert.AreEqual(view.DesiredJobTitle, model.DesiredJobTitle);
            Assert.AreEqual(view.DesiredJobTypes, model.DesiredJobTypes);

            Assert.AreEqual(view.Resume == null ? null : view.Resume.Summary, model.Summary);

            if (view.Resume == null || view.Resume.Jobs == null || view.Resume.Jobs.Count == 0)
            {
                Assert.IsNull(model.Jobs);
            }
            else
            {
                for (var index = 0; index < view.Resume.Jobs.Count; ++index)
                {
                    AssertJob(view.Resume.Jobs[index], model.Jobs[index]);
                }
            }
        }
Example #2
0
        public static bool IsNotAlreadyLogged(StateResultsModel stateResults, CandidateModel bernieResult,
                                              CandidateModel clintonResult)
        {
            using (
                SqlConnection sqlCon =
                    new SqlConnection(
                        System.Configuration.ConfigurationManager.ConnectionStrings["local"].ConnectionString))
            {
                sqlCon.Open();

                SqlCommand duplicateCheck = new SqlCommand
                {
                    CommandText =
                        "SELECT [BernieVotes], [ClintonVotes],[UpdatedAt] FROM dbo.[CaStateResults] WHERE BernieVotes = @BernieVotes AND ClintonVotes = @ClintonVotes AND UpdatedAt = @UpdatedAt",
                    Connection = sqlCon
                };

                duplicateCheck.Parameters.AddWithValue("@BernieVotes", bernieResult.Votes);
                duplicateCheck.Parameters.AddWithValue("@ClintonVotes", clintonResult.Votes);
                duplicateCheck.Parameters.AddWithValue("@UpdatedAt", stateResults.UpdatedAt);

                SqlDataReader reader = duplicateCheck.ExecuteReader();

                return(reader.HasRows);
            }
        }
Example #3
0
        public async Task <ActionResult <CandidateModel> > PostCandidateModel(CandidateModel candidateModel)
        {
            _context.CandidateModels.Add(candidateModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCandidateModel", new { id = candidateModel.ID }, candidateModel));
        }
Example #4
0
 private CandidateViewModel MapToCandidateViewModel(CandidateModel domainModel)
 {
     return(new CandidateViewModel
     {
         ID = domainModel.ID,
         FirstName = domainModel.FirstName,
         LastName = domainModel.LastName,
         MiddleName = domainModel.MiddleName,
         FinCode = domainModel.FinCode,
         Mail = domainModel.Mail,
         Birthdate = domainModel.Birthdate,
         ExamDate = domainModel.ExamDate,
         ExamTime = domainModel.ExamTime,
         FamilyStatusId = domainModel.FamilyStatusId,
         GenderId = domainModel.GenderId,
         Profession = domainModel.Profession,
         ProfessionId = domainModel.ProfessionId,
         ExamProfessionId = domainModel.ExamProfessionId,
         Mobile = domainModel.Mobile,
         Status = domainModel.Status,
         Description = domainModel.Description,
         LocalCandidateStatus = domainModel.LocalCandidateStatus,
         Finish = domainModel.Finish,
         TicketId = domainModel.TicketID
     });
 }
Example #5
0
        private async void btnEdit_Click(object sender, EventArgs e)
        {
            Opacity = 0.5;

            var editCandidate = new CandidateForm();

            editCandidate.EditingCandidate = CurrentCandidate;
            editCandidate.Owner            = this;
            editCandidate.ShowDialog();

            var candidate = await editCandidate.GetNewDataAsync();

            if (candidate != null)
            {
                IsUpdated = true;

                CurrentCandidate = candidate;
                SetCandidate();

                await _window.LoadCandidatesAsync();

                _candidateParty = (await _candidateService.GetCandidateDetailsListByPartyAsync(CurrentCandidate.PartyId)).ToList();

                _index = _candidateParty.FindIndex(c => c.Id == candidate.Id);
                lblCandidatePage.Text = (_index + 1) + " of " + (_candidateParty.Count);

                btnNext.Enabled = _index != _candidateParty.Count - 1;
                btnPrev.Enabled = _index != 0;
            }

            Opacity = 1;
        }
        public ActionResult <CandidateModel> GetCandidate(int id)
        {
            var candidateEntity = _interviewService.GetCandidate(id);

            if (candidateEntity == null)
            {
                return(NotFound($"No Candidate of id {id} exists"));
            }

            var retVal = new CandidateModel()
            {
                Id           = id,
                FirstName    = candidateEntity.FirstName,
                LastName     = candidateEntity.LastName,
                PositionType = candidateEntity.PositionType,
                Created      = candidateEntity.Created
            };

            if (candidateEntity.Tests.Any())
            {
                retVal.Tests = new List <CandidateTestModel>();
                foreach (var test in candidateEntity.Tests)
                {
                    retVal.Tests.Add(new CandidateTestModel(test));
                }
            }

            return(retVal);
        }
Example #7
0
 public ActionResult AddNameSubmit(CandidateModel cm)
 {
     try
     {
         cm.BidCount  = 0;
         cm.Hidden    = 1;
         cm.Priority  = 0;
         cm.BidAdjust = 0;
         CandidateRepository cr = new CandidateRepository();
         int duplicateId        = cr.CheckDuplicate(cm);
         if (duplicateId == -2)
         {
             return(Json(new { success = false, message = "提名失败,被提名对象已经存在。如果在投票页面上没有见到,可能处于审核状态。" }));
         }
         if (duplicateId != -1)
         {
             cm.Type = cm.Type + 10 * duplicateId;
         }
         cr.Insert(cm);
         cr.Save();
         return(Json(new { success = true }));
     }
     catch (Exception e)
     {
         return(Json(new { success = false, message = e.Message }));
     }
 }
        // POST: api/Candidates
        public ResponseModel Post([FromBody] CandidateModel Candidate)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ResponseModel Response = _ICandidatesRepository.CreateCandidate(Candidate);

                    if (Response.ID > 0)
                    {
                        return(Response);
                    }
                    else
                    {
                        return(Helpers.ResponseFactory.Create(false));
                    }
                }
                else
                {
                    ResponseModel ErrorResponse = Helpers.ResponseFactory.Create(false);
                    ErrorResponse.Message = "Candidate information is incorrect. Please take a look at the details.";
                    ErrorResponse.Object  = ModelState.Values.SelectMany(v => v.Errors);
                    return(ErrorResponse);
                }
            }
            catch (Exception ex)
            {
                Helpers.Utils.RegisterException("Candidates: Post", ex.Message);
                return(Helpers.ResponseFactory.Create(false));
            }
        }
Example #9
0
        public bool CreateNewCandidate(int[] skills, CandidateModel candidate)
        {
            bool result       = true;
            var  NewCandidate = new Candidate()
            {
                FirstName = candidate.FirstName,
                LastName  = candidate.LastName,
            };

            work.Candidates.Add(NewCandidate);
            if (skills != null)
            {
                for (int i = 0; i < skills.Length; i++)
                {
                    var skill = new Candidate_Skills()
                    {
                        CandidateId = NewCandidate.Id,
                        SkillId     = skills[i]
                    };
                    work.CandidateSkills.Add(skill);
                }
            }
            work.Commit();
            return(result);
        }
Example #10
0
        public static void LogChanges(StateResultsModel stateResults, CandidateModel bernieResult,
                                      CandidateModel clintonResult)
        {
            using (
                SqlConnection sqlCon =
                    new SqlConnection(
                        System.Configuration.ConfigurationManager.ConnectionStrings["local"].ConnectionString))
            {
                sqlCon.Open();

                SqlCommand sqlCmd1 = new SqlCommand
                {
                    CommandText =
                        "INSERT INTO dbo.[CaStateResults] ([BernieVotes], [ClintonVotes], [UpdatedAt]) VALUES (@BernieVotes, @ClintonVotes, @UpdatedAt)",
                    Connection = sqlCon
                };

                sqlCmd1.Parameters.AddWithValue("@BernieVotes", bernieResult.Votes);
                sqlCmd1.Parameters.AddWithValue("@ClintonVotes", clintonResult.Votes);
                sqlCmd1.Parameters.AddWithValue("@UpdatedAt", stateResults.UpdatedAt);
                sqlCmd1.ExecuteNonQuery();

                sqlCon.Close();
            }

            Console.WriteLine("New votes recorded");
        }
Example #11
0
        // GET: Candidate/Details/5
        public ActionResult DetailsCandidate(int id)
        {
            CandidateModel cm     = new CandidateModel();
            candidate      can    = new candidate();
            HttpClient     client = new HttpClient();

            client.BaseAddress = new Uri("http://*****:*****@"""" + s + @"""";
                can.dateNaissance = cm.dateNaissance;
            }
            Console.WriteLine(can);
            return(View(can));
        }
Example #12
0
        public ActionResult CandidateDelete(string id)
        {
            CandidateModel comm    = new CandidateModel();
            bool           statuss = comm.DeleteCandidate(id);

            return(RedirectToAction("Candidate", "Candidate"));
        }
Example #13
0
        public async Task ValidateAsync(int electionId, CandidateModel candidate)
        {
            if (string.IsNullOrWhiteSpace(candidate.FirstName))
            {
                throw new ArgumentException("No first name provided");
            }

            if (string.IsNullOrWhiteSpace(candidate.LastName))
            {
                throw new ArgumentException("No last name provided");
            }

            if (candidate.YearLevel < 1 || candidate.YearLevel > 12)
            {
                throw new ArgumentOutOfRangeException("Year level must be from 1 to 12");
            }

            if (string.IsNullOrWhiteSpace(candidate.Section))
            {
                throw new ArgumentException("No section provided");
            }

            if (string.IsNullOrWhiteSpace(candidate.Alias))
            {
                throw new ArgumentException("No alias provided");
            }

            if (await IsAliasExistingAsync(electionId, candidate.Alias, null))
            {
                throw new InvalidOperationException($"Alias '{ candidate.Alias }' already exists");
            }
        }
Example #14
0
        public ActionResult Create(
            CandidateModel candidateModel,
            HttpPostedFileBase imageUrl)
        {
            var campaignIds = dao.GetAllCampaignID();

            candidateModel.CampaignIds = GetSelectListItems(campaignIds);
            int count = 0;

            if (ModelState.IsValid)
            {
                var fileName  = Path.GetFileName(imageUrl.FileName);
                var directory = Server.MapPath(Url.Content("~/Content/Images"));
                var path      = Path.Combine(directory, fileName);
                imageUrl.SaveAs(path);
                candidateModel.ImageUrl = fileName;
                count = dao.InsertCandidate(candidateModel);
                if (count == 1)
                {
                    ViewBag.Message = "Candidate added!";
                    return(View("Success"));
                }
                else
                {
                    ViewBag.Message = $"Error {dao.message}";
                    return(View("Error"));
                }
            }
            else
            {
                return(View(candidateModel));
            }
        }
Example #15
0
        public ActionResult EditApply(int id)
        {
            CandidateRepository cr = new CandidateRepository();
            CandidateModel      cm = cr.GetInfoById(id);

            return(View(cm));
        }
 public ActionResult Save(CandidateModel Candidate)
 {
     if (ModelState.IsValid)
     {
         using (MyDbContext dc = new MyDbContext())
         {
             if (Candidate.ID > 0)
             {
                 //Edit
                 var v = dc.tblCandidate.Where(a => a.ID == Candidate.ID).FirstOrDefault();
                 if (v != null)
                 {
                     v.FirstName  = Candidate.FirstName;
                     v.SecondName = Candidate.SecondName;
                     v.LastName   = Candidate.LastName;
                     v.Region     = Candidate.Region;
                     v.District   = Candidate.District;
                     v.Party      = Candidate.Party;
                     v.Election   = Candidate.Election;
                 }
             }
             else
             {
                 //Save
                 dc.tblCandidate.Add(Candidate);
             }
             dc.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View());
 }
Example #17
0
        public ActionResult Candidate()
        {
            CandidateModel candiModel = new CandidateModel();

            candiModel.GetCountry();
            candiModel.GetCandidateList();
            return(View(candiModel));
        }
Example #18
0
        // GET: Create
        public ActionResult Create()
        {
            var campaignIds = dao.GetAllCampaignID();
            var model       = new CandidateModel();

            model.CampaignIds = GetSelectListItems(campaignIds);
            return(View(model));
        }
Example #19
0
        /// <summary>
        /// Service Method To Get All The Candidates
        /// </summary>
        /// <param name="candidate"></param>
        /// <returns></returns>
        public static async Task <List <CandidateModel> > GetCandidates(CandidateModel candidate)
        {
            List <CandidateModel> Candidates = new List <CandidateModel>();

            using (SqlConnection dbConn = new SqlConnection(selectConnection(candidate.Location)))
            {
                var           Query = "SELECT * from Candidate";
                SqlDataReader reader;

                try
                {
                    dbConn.Open();
                    SqlCommand cmd = new SqlCommand(Query, dbConn);
                    reader = await cmd.ExecuteReaderAsync();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            CandidateModel candidateItem = new CandidateModel();
                            candidateItem.ID         = reader.GetInt32(0);
                            candidateItem.Name       = reader.GetString(1);
                            candidateItem.PartyID    = reader.GetInt32(2);
                            candidateItem.DistrictID = reader.GetInt32(3);
                            candidateItem.Votes      = reader.GetInt32(4);
                            Candidates.Add(candidateItem);
                        }
                    }
                }
                catch (Exception ex)
                {
                    reader = null;
                    ActionLogService.LogAction(new ActionLogModel()
                    {
                        UserID          = candidate.UserID,
                        ActionPerformed = "Candidates Error : " + ex.Message,
                        MethodName      = "GetCandidates",
                        IsError         = true
                    },
                                               candidate.Location);
                }
                finally
                {
                    dbConn.Close();
                    ActionLogService.LogAction(new ActionLogModel()
                    {
                        UserID          = candidate.UserID,
                        ActionPerformed = "Get All Existing Candidates ",
                        MethodName      = "GetCandidates",
                        IsError         = false
                    },
                                               candidate.Location);
                }

                return(Candidates);
            }
        }
Example #20
0
        /// <summary>
        /// Service Method To Get All The Candidates (Since All The Locations Will Have The Same candidates, Can Get Them From One Location)
        /// </summary>
        /// <param name="location"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static List <CandidateModel> GetCandidates(string location, int userID)
        {
            List <CandidateModel> candidates = new List <CandidateModel>();

            using (SqlConnection dbConn = new SqlConnection(selectConnection(location)))
            {
                string query = @"SELECT * FROM Candidate";

                SqlDataReader reader;

                try
                {
                    dbConn.Open();
                    SqlCommand cmd = new SqlCommand(query, dbConn);
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            CandidateModel candidate = new CandidateModel();
                            candidate.ID    = reader.GetInt32(0);
                            candidate.Name  = reader.GetString(1);
                            candidate.Votes = reader.GetInt32(2);

                            candidates.Add(candidate);
                        }
                    }
                }
                catch (Exception ex)
                {
                    reader = null;
                    ActionLogService.LogAction(new ActionLogModel()
                    {
                        UserID          = userID,
                        ActionPerformed = " Error In Consolidating Votes : " + ex.Message,
                        MethodName      = "ConsolidateVotes",
                        IsError         = true
                    },
                                               location);
                }
                finally
                {
                    dbConn.Close();
                    ActionLogService.LogAction(new ActionLogModel()
                    {
                        UserID          = userID,
                        ActionPerformed = "Consolidate Votes",
                        MethodName      = "ConsolidateVotes",
                        IsError         = false
                    },
                                               location);
                }

                return(candidates);
            }
        }
Example #21
0
        public static void Put(int id, CandidateModel candidateModel)
        {
            TestOnlineEntities entities = new TestOnlineEntities();
            var updatedCandidate        = entities.Candidate.FirstOrDefault(c => c.Id == id);

            updatedCandidate.LastName  = candidateModel.LastName;
            updatedCandidate.FirstName = candidateModel.FirstName;

            entities.SaveChanges();
        }
Example #22
0
        public ActionResult Create(CandidateModel model)
        {
            try
            {
                var newPerson = new Person
                {
                    Email     = model.Email,
                    PhoneNo   = model.Phone,
                    FirstName = !string.IsNullOrEmpty(model.FirstName) ? model.FirstName : "Unknown",
                    LastName  = !string.IsNullOrEmpty(model.LastName) ? model.LastName : "Unknown"
                };

                _personRepository.Create(newPerson);

                var newCandidate = new Candidate
                {
                    Source          = model.Source,
                    Status          = CandidateStatus.New,
                    PersonId        = newPerson.Id,
                    RecievedOn      = DateTime.UtcNow,
                    CreatedByUserId = model.CreatedByUserId,
                    Comments        = model.Comments
                };

                _candidateRepository.Create(newCandidate);
                _unitOfWork.Commit();

                // Update the Candidate Code.
                var selectedCandidate = _candidateRepository.Get(newCandidate.Id);
                if (selectedCandidate != null)
                {
                    selectedCandidate.Code = $"LA{selectedCandidate.Id.ToString("D" + 6)}";
                    _candidateRepository.Update(selectedCandidate);
                    _unitOfWork.Commit();
                }

                var result = new ApiResult <bool>
                {
                    Status  = true,
                    Message = "Success"
                };

                return(Json(result));
            }
            catch (Exception ex)
            {
                var result = new ApiResult <bool>
                {
                    Status  = false,
                    Message = ex.Message
                };

                return(Json(result));
            }
        }
Example #23
0
        public ActionResult GetEditBase(int id)
        {
            CandidateRepository cr = new CandidateRepository();
            CandidateModel      cm = cr.GetInfoById(id);

            if (HttpContext.User.Identity.Name != "Super")
            {
                cm.BidAdjust = 0;
            }
            return(Json(cm));
        }
Example #24
0
        public async Task UpdateCandidateAsync(CandidateModel model)
        {
            using (var context = new StudentElectionContext())
            {
                var candidate = await context.Candidates.SingleOrDefaultAsync(c => c.Id == model.Id);

                _mapper.Map(model, candidate);

                await context.SaveChangesAsync();
            }
        }
Example #25
0
 public async Task SaveCandidateAsync(CandidateModel candidate)
 {
     if (candidate.Id == 0)
     {
         await _candidateRepository.InsertCandidateAsync(candidate);
     }
     else
     {
         await _candidateRepository.UpdateCandidateAsync(candidate);
     }
 }
Example #26
0
        public async Task DeleteCandidateAsync(CandidateModel model)
        {
            using (var context = new StudentElectionContext())
            {
                var candidate = await context.Candidates.SingleOrDefaultAsync(c => c.Id == model.Id);

                context.Candidates.Remove(candidate);

                await context.SaveChangesAsync();
            }
        }
Example #27
0
        public ActionResult AddNewCandidate(CandidateMV candiate, int[] skills)
        {
            var createNew = new CandidateModel()
            {
                FirstName = candiate.FirstName,
                LastName  = candiate.LastName
            };
            var result = crsService.CreateNewCandidate(skills, createNew);

            return(RedirectToAction("Index"));
        }
Example #28
0
        public async Task DeleteCandidateAsync(CandidateModel candidate)
        {
            await Task.CompletedTask;

            using (var tableAdapter = new CandidateTableAdapter())
            {
                tableAdapter.Delete(
                    candidate.Id
                    );
            }
        }
Example #29
0
        public int SaveCandidate(CandidateModel model)
        {
            int candId = this.DataContext.SaveCandidate(model.Candidate);

            if (!string.IsNullOrWhiteSpace(model.Resume.ResumePath))
            {
                model.Resume.CandidateID = candId;
                return(this.DataContext.SaveResume(model.Resume));
            }
            return(candId);
        }
        public async Task <HttpResponseMessage> Add()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var root = HttpContext.Current.Server.MapPath("~/Assets/Uploads");

            Directory.CreateDirectory(root);
            var provider = new CustomMultipartFormDataStreamProvider(root);
            var result   = await Request.Content.ReadAsMultipartAsync(provider);

            if (result.FormData["model"] == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var            model      = result.FormData["model"];
            var            serializer = new JavaScriptSerializer();
            CandidateModel modelToAdd = serializer.Deserialize <CandidateModel>(model);

            string pattern = @"^[A-Za-z ]+$";
            Regex  regex   = new Regex(pattern);

            if (!regex.IsMatch(modelToAdd.name))
            {
                HttpResponseMessage response = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Name must only contains letters and white space");
                throw new HttpResponseException(response);
            }

            if (!regex.IsMatch(modelToAdd.sur_name))
            {
                HttpResponseMessage response = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Surname must only contains letters and white space");
                throw new HttpResponseException(response);
            }

            candidate obj = new candidate();

            obj.name     = modelToAdd.name;
            obj.sur_name = modelToAdd.sur_name;
            obj.position = modelToAdd.position;

            //get the files
            //TODO: Do something with each uploaded file
            foreach (var file in result.FileData)
            {
                obj.curriculum = Path.GetFileName(file.LocalFileName);
            }
            obj.Insert();

            return(Request.CreateResponse(HttpStatusCode.OK, obj));
        }