Пример #1
0
        public List <SelectListItem> GetCandidateDropDownItems()
        {
            var candidateList = new List <CandidateItem>();
            var dropDownList  = new List <SelectListItem>();

            foreach (var dbItem in db.Candidates)
            {
                CandidateItem item = new CandidateItem
                {
                    CandidateID      = dbItem.CandidateID,
                    CourtID          = dbItem.CourtID,
                    SpecializationID = dbItem.SpecializationID,
                    FirstName        = dbItem.FirstName,
                    LastName         = dbItem.LastName,
                    MiddleName       = dbItem.MiddleName,
                    GenderID         = dbItem.GenderID,
                    BirthDate        = dbItem.BirthDate
                };
                candidateList.Add(item);
            }

            dropDownList = candidateList.Select(x => new SelectListItem {
                Text = x.CandidateName, Value = x.CandidateID.ToString()
            }).ToList();
            return(dropDownList);
        }
Пример #2
0
        public CandidateItem GetCandidate(int?candidateID = null)
        {
            if (candidateID != null)
            {
                var dbItem = (from candidate in db.Candidates
                              join t1 in db.Specializations on candidate.SpecializationID equals t1.SpecializationID into r1
                              from specialization in r1.DefaultIfEmpty()
                              join t2 in db.Genders on candidate.GenderID equals t2.GenderID into r2
                              from gender in r2.DefaultIfEmpty()
                              join t3 in db.Courts on candidate.CourtID equals t3.CourtID into r3
                              from court in r3.DefaultIfEmpty()
                              where candidate.CandidateID == candidateID
                              select new { candidateTable = candidate, specializationTable = specialization, genderTable = gender, courtTable = court })
                             .Select(list => new CandidateItem
                {
                    CandidateID        = list.candidateTable.CandidateID,
                    FirstName          = list.candidateTable.FirstName,
                    LastName           = list.candidateTable.LastName,
                    MiddleName         = list.candidateTable.MiddleName,
                    BirthDate          = list.candidateTable.BirthDate,
                    CourtID            = list.candidateTable.CourtID,
                    CourtName          = list.courtTable.CourtName,
                    GenderID           = list.candidateTable.GenderID,
                    GenderName         = list.genderTable.GenderName,
                    SpecializationID   = list.candidateTable.SpecializationID,
                    SpecializationName = list.specializationTable.SpecializationName
                }).First();


                CandidateItem item = new CandidateItem
                {
                    CandidateID        = dbItem.CandidateID,
                    CourtID            = dbItem.CourtID,
                    SpecializationID   = dbItem.SpecializationID,
                    FirstName          = dbItem.FirstName,
                    LastName           = dbItem.LastName,
                    MiddleName         = dbItem.MiddleName,
                    BirthDate          = dbItem.BirthDate,
                    GenderID           = dbItem.GenderID,
                    GenderName         = dbItem.GenderName,
                    SpecializationName = dbItem.SpecializationName,
                    CourtName          = dbItem.CourtName
                };
                return(item);
            }
            else
            {
                var item = new CandidateItem();
                return(item);
            }
        }
Пример #3
0
        public CandidateItem UpdateCandidate(CandidateItem item)
        {
            Candidate dbItem = db.Candidates.Find(item.CandidateID);

            dbItem.CandidateID      = (int)item.CandidateID;
            dbItem.CourtID          = item.CourtID;
            dbItem.SpecializationID = item.SpecializationID;
            dbItem.FirstName        = item.FirstName;
            dbItem.LastName         = item.LastName;
            dbItem.MiddleName       = item.MiddleName;
            dbItem.BirthDate        = item.BirthDate;
            dbItem.GenderID         = item.GenderID;
            db.Candidates.Attach(dbItem);
            db.Entry(dbItem).State = EntityState.Modified;
            db.SaveChanges();
            return(item);
        }
Пример #4
0
        public CandidateItem InsertCandidate(CandidateItem item)
        {
            Candidate dbItem = new Candidate
            {
                CourtID          = item.CourtID,
                SpecializationID = item.SpecializationID,
                FirstName        = item.FirstName,
                LastName         = item.LastName,
                MiddleName       = item.MiddleName,
                BirthDate        = item.BirthDate,
                GenderID         = item.GenderID
            };

            db.Candidates.Add(dbItem);
            db.SaveChanges();
            item.CandidateID = dbItem.CandidateID;
            return(item);
        }
Пример #5
0
        public List <SelectListItem> GetFilteredCandidateDropDownItems(int?courtID, string candidateName, int credentialID)
        {
            var candidateList = new List <CandidateItem>();
            var dropDownList  = new List <SelectListItem>();

            var q = from p in db.Candidates select p;

            if (courtID != null)
            {
                q = from p in q where p.CourtID == courtID select p;
            }
            if (!string.IsNullOrEmpty(candidateName))
            {
                q = from p in q where p.LastName.Contains(candidateName) select p;
            }

            foreach (var dbItem in q)
            {
                CandidateItem item = new CandidateItem
                {
                    CandidateID      = dbItem.CandidateID,
                    CourtID          = dbItem.CourtID,
                    SpecializationID = dbItem.SpecializationID,
                    FirstName        = dbItem.FirstName,
                    LastName         = dbItem.LastName,
                    MiddleName       = dbItem.MiddleName,
                    GenderID         = dbItem.GenderID,
                    BirthDate        = dbItem.BirthDate
                };

                var excludeItem = from p in db.Results where p.CredentialID == credentialID && p.CandidateID == dbItem.CandidateID select p;
                if (excludeItem.Count() == 0)
                {
                    candidateList.Add(item);
                }
            }

            dropDownList = candidateList.Select(x => new SelectListItem {
                Text = x.CandidateName, Value = x.CandidateID.ToString()
            }).ToList();
            return(dropDownList);
        }