public void UpdateAttemptedQuestion(ParticipantDetail objParticipantDetails) { using (DBModel db = new DBModel()) { int ParticipantID = db.Participants.OrderByDescending(i => i.ParticipantID).Select(p => p.ParticipantID).FirstOrDefault(); //int ParticipantID = (from a in db.Participants // orderby a.ParticipantID // select a.ParticipantID).First(); objParticipantDetails.ParticipantID = ParticipantID; objParticipantDetails.SubmissionTime = System.DateTime.Now; //db.ParticipantDetails.InsertOnSubmit(objParticipantDetails); //db.SubmitChanges(); db.ParticipantDetails.Add(objParticipantDetails); db.SaveChanges(); } }
public ParticipantViewModel GetPerson(int id, int studyId) { var participant = new ParticipantViewModel(); var mapper = new ParticipantMapper(); var personDetail = new ParticipantDetail(); var person = new ParticipantById(); if (studyId == 0) { person = db.GetParticipantById(id).FirstOrDefault(); } else { person = db.GetParticipantById(id).Where(s => s.StudyId == studyId).FirstOrDefault(); } if (person != null) { participant = mapper.GetParticipantViewModel(person); //HouseholdMembers if (participant.HouseholdId != null) { var participantList = GetPeople(); participant.HouseholdMembers = participantList.Where(p => p.HouseholdId == participant.HouseholdId).ToList(); } if (studyId != 0) { #region StudyParticipation var ic = db.GetParticipantConsentById(participant.PersonId).Where(s => s.StudyId == participant.StudyId).ToArray(); var informedConsents = Mapper.Map <ParticipantConsentById[], IEnumerable <LinkedInformedConsentViewModel> >(ic); foreach (var i in informedConsents) { if (i.WrittenConsentBy.HasValue) { i.WrittenConsenByName = db.uspGetStaffFullNameById(i.WrittenConsentBy.Value).FirstOrDefault(); } if (i.VerbalConsentBy.HasValue) { i.VerbalConsentByName = db.uspGetStaffFullNameById(i.VerbalConsentBy.Value).FirstOrDefault(); } } participant.InformedConsents = informedConsents.ToList(); #endregion //Corresponsdance #region Corresponsdance var userCorrespondance = db.Correspondences.Where(c => c.StudyId == studyId && c.PersonId == id).ToArray(); var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance); foreach (var c in correspondance) { if (c.VtgStaffId.HasValue) { c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault(); } if (c.FollowupStaff1.HasValue) { c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault(); } if (c.FollowupStaff2.HasValue) { c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault(); } } participant.Correspondance = correspondance; #endregion #region Medical History var medHistory = db.MedicalHistories.Where(m => m.PersonId == id).ToArray(); var medicalHistory = Mapper.Map <MedicalHistory[], IEnumerable <MedicalHistoryViewModel> >(medHistory); foreach (var md in medicalHistory) { } participant.MedicalHistory = medicalHistory; #endregion } else { #region Corresponsdance var userCorrespondance = db.Correspondences.Where(c => c.StudyId == null && c.PersonId == id).ToArray(); var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance); foreach (var c in correspondance) { if (c.VtgStaffId.HasValue) { c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault(); } if (c.FollowupStaff1.HasValue) { c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault(); } if (c.FollowupStaff2.HasValue) { c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault(); } } participant.Correspondance = correspondance; #endregion } #region Practices/Doctors var linkedDocPractice = db.LinkSubjectDoctorPractices.Where(d => d.PersonId == id).ToList(); var linkedDocPracticeVM = Mapper.Map <List <LinkSubjectDoctorPractice>, IEnumerable <LinkedSubjectDoctorPracticeViewModel> >(linkedDocPractice); foreach (var link in linkedDocPracticeVM) { var practiceDocs = db.LinkDoctorPractices.Where(p => p.DoctorPracticeLinkId == link.DoctorPracticeLinkId).FirstOrDefault(); //PracticeName link.Practice = db.Practices.Where(p => p.PracticeId == practiceDocs.PracticeId).Select(p => p.NamePractice).FirstOrDefault(); link.PracticeId = practiceDocs.PracticeId; //Doctor Detail var doctor = db.Doctors.Where(d => d.DoctorId == practiceDocs.DoctorId).FirstOrDefault(); link.DoctorId = practiceDocs.DoctorId; link.DoctorName = doctor.Fullname; link.DoctorType = doctor.TypeDoctor; } participant.LinkedSubjectDoctorPractices = linkedDocPracticeVM; #endregion //Next of Kins //if (person.Nok1PersonId != null) //{ // participant.Nok1PersonId = person.Nok1PersonId; // participant.Nok1Person = person.NoK1Person; //} //if (person.Nok2PersonId != null) //{ // participant.Nok2PersonId = person.Nok2PersonId; // participant.Nok2Person = person.NoK2Person; //} } return(participant); }
//public StaffEventCreation GetEventByYakkrId(string YakkrId) //{ // StaffEventCreation evt = new StaffEventCreation(); // StaffDetails staffDetails = StaffDetails.GetInstance(); // try // { // if (Connection.State == ConnectionState.Open) // Connection.Close(); // command.Connection = Connection; // command.CommandType = CommandType.StoredProcedure; // _dataset = new DataSet(); // command.Parameters.Clear(); // command.Parameters.Add(new SqlParameter("@Agencyid", staffDetails.AgencyId)); // command.Parameters.Add(new SqlParameter("@userid", staffDetails.UserId)); // command.Parameters.Add(new SqlParameter("@yakkrid", YakkrId)); // command.CommandText = "SP_GetEventByEventId"; // SqlDataAdapter da = new SqlDataAdapter(command); // da.Fill(_dataset); // Connection.Close(); // if (_dataset != null) // { // if (_dataset.Tables[0].Rows.Count > 0) // { // evt.CreatedBy = _dataset.Tables[0].Rows[0]["StaffName"].ToString(); // evt.EventDate = _dataset.Tables[0].Rows[0]["EventDateTime"].ToString(); // evt.EventName = _dataset.Tables[0].Rows[0]["TrainingName"].ToString(); // evt.EventDescription = _dataset.Tables[0].Rows[0]["description"].ToString(); // evt.CancelReason = _dataset.Tables[0].Rows[0]["cancellreason"].ToString(); // } // } // } // catch (Exception ex) // { // clsError.WriteException(ex); // } // return evt; //} public EventReportDetails GetEventReportByID(int eventType, int eventId, int mode, string search = "", string CheckInUserId = null, string AgencyId = null, string ManagerId = null) { EventReportDetails evtDetails = new EventReportDetails(); evtDetails.ParticipantDetails = new List <ParticipantDetail>(); StaffDetails staffDetails = StaffDetails.GetInstance(); try { if (Connection.State == ConnectionState.Open) { Connection.Close(); } command.Connection = Connection; command.CommandType = CommandType.StoredProcedure; _dataset = new DataSet(); command.Parameters.Clear(); command.Parameters.Add(new SqlParameter("@AgencyId", staffDetails.AgencyId)); command.Parameters.Add(new SqlParameter("@EventId", eventId)); command.Parameters.Add(new SqlParameter("@EventType", eventType)); command.Parameters.Add(new SqlParameter("@Mode", mode)); command.Parameters.Add(new SqlParameter("@Userid", staffDetails.UserId)); command.Parameters.Add(new SqlParameter("@Search", search)); command.Parameters.Add(new SqlParameter("@CheckInUserId", CheckInUserId)); command.CommandText = "GetEventReportByID"; SqlDataAdapter da = new SqlDataAdapter(command); da.Fill(_dataset); Connection.Close(); if (_dataset != null) { if (_dataset.Tables[0].Rows.Count > 0) { evtDetails.Eventid = Convert.ToInt32(_dataset.Tables[0].Rows[0]["EventID"]); evtDetails.Trainer = _dataset.Tables[0].Rows[0]["Trainer"].ToString(); evtDetails.EventName = _dataset.Tables[0].Rows[0]["TrainingName"].ToString(); evtDetails.EventDescription = _dataset.Tables[0].Rows[0]["Description"].ToString(); evtDetails.EventDate = _dataset.Tables[0].Rows[0]["TrainingDate"].ToString(); evtDetails.EventAddress = _dataset.Tables[0].Rows[0]["EventAddress"].ToString(); // evtDetails.IsTodayEvent = Convert.ToInt32(_dataset.Tables[0].Rows[0]["EventAddress"]); if (_dataset.Tables.Count > 1 && _dataset.Tables[1].Rows.Count > 0) { foreach (DataRow item in _dataset.Tables[1].Rows) { var _pDetail = new ParticipantDetail() { ParticipantId = item["UserId"].ToString(), ParticipantName = item["Name"].ToString(), ParticipantRoleName = item["RoleName"].ToString(), RSVPStatusModifiedDate = item["RSVPStatusModifiedDate"].ToString() == "" ? "--" : item["RSVPStatusModifiedDate"].ToString(), RSVPStatusName = item["RSVPStatus"].ToString(), RSVPStatusId = DBNull.Value == item["RSVPStatusId"] ? -1 : Convert.ToInt32(item["RSVPStatusId"]), }; if (mode == 2) { _pDetail.Signature = DBNull.Value == item["Signature"] ? "" : item["Signature"].ToString(); _pDetail.IsAttended = DBNull.Value == item["IsAttended"] ? -1 : Convert.ToInt32(item["IsAttended"]); _pDetail.Avatar = item["Avatar"].ToString(); } if (mode == 3) { _pDetail.Avatar = item["Avatar"].ToString(); _pDetail.Gender = DBNull.Value == item["Gender"] ? -1 : Convert.ToInt32(item["Gender"]); } evtDetails.ParticipantDetails.Add(_pDetail); //evtDetails.ParticipantDetails.Add(new ParticipantDetail() // { // ParticipantId = item["UserId"].ToString(), // ParticipantName = item["Name"].ToString(), // ParticipantRoleName = item["RoleName"].ToString(), // RSVPStatusModifiedDate= item["RSVPStatusModifiedDate"].ToString()==""?"--": item["RSVPStatusModifiedDate"].ToString(), // RSVPStatusName = item["RSVPStatus"].ToString(), // RSVPStatusId = DBNull.Value == item["RSVPStatusId"] ? -1 : Convert.ToInt32(item["RSVPStatusId"]) // }); } } if (mode == 1 && eventType == 1) { evtDetails.ParticipantCount = evtDetails.ParticipantDetails.Count(x => x.RSVPStatusId == 1); } else if (mode == 1 && eventType == 2) { evtDetails.ParticipantCount = evtDetails.ParticipantDetails.Count(x => x.RSVPStatusName == "Attended" || x.RSVPStatusName == "Walk-in"); } else if (mode == 2) { evtDetails.ParticipantCount = evtDetails.ParticipantDetails.Count(x => x.IsAttended == 1); } } } } catch (Exception ex) { clsError.WriteException(ex); } return(evtDetails); }