Пример #1
0
        private static void Getvalidators()
        {
            using var context = new Context();
            JArray list   = Helper.GetValidators();
            var    result = new List <CandidateViewModels>();

            foreach (JObject item in list)
            {
                var c = CandidateViewModels.FromJson(item);
                c.Info = context.Candidates.FirstOrDefault(p => p.PublicKey == c.PublicKey);
                result.Add(c);
            }
            var text = JsonConvert.SerializeObject(result.OrderByDescending(p => p.Votes).Select(p => new
            {
                p.PublicKey,
                p.Votes,
                Info = p.Info == null ? null : new
                {
                    p.Info.Organization,
                    p.Info.Logo,
                    p.Info.Email,
                    p.Info.Website,
                    p.Info.SocialAccount,
                    p.Info.Summary
                },
                p.Active
            }));

            SaveFile("validators.json", text);
        }
Пример #2
0
        /// <summary>
        /// return a candidate by id's
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CandidateViewModels GetCandidateById(int id)
        {
            CandidateViewModels candidate = new CandidateViewModels();

            try
            {
                using (QuizContext db = new QuizContext())
                {
                    candidate = db.Candidates.Find(id).MapToCandidateViewModels();
                }
            }
            catch (Exception ex)
            {
            }

            return(candidate);
        }
Пример #3
0
        /// <summary>
        /// Add new Candidate
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddNewCandidate(CandidateViewModels candidateViewModel)
        {
            try
            {
                using (QuizContext db = new QuizContext())
                {
                    var candidate = candidateViewModel.MapToCandidate();// à faire: remplacer par la methode mapping de amine
                    db.Candidates.Add(candidate);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }

            return(0);
        }
Пример #4
0
        public static CandidateViewModels MapToCandidateViewModels(this Candidate candidate)
        {
            var candidateVM = new CandidateViewModels();

            if (candidate == null)
            {
                return(candidateVM);
            }

            candidateVM = new CandidateViewModels()
            {
                CandidateID = candidate.CandidateID,
                LastName    = candidate.LastName,
                FirstName   = candidate.FirstName,
                PhoneNumber = candidate.PhoneNumber,
                Email       = candidate.Email,
                EmployeeId  = candidate.EmployeeId
            };
            return(candidateVM);
        }