public ServiceResult <long> CreateNewConversation(AddConversationDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; long result = -1; try { var newConversation = new Conversation { SenderId = model.SenderId, ReceiverId = model.ReceiverId, Message = model.Message, Date = DateTime.Now }; var conversationResult = _conversationRepository.Add(newConversation); _unitOfWork.SaveChanges(); result = conversationResult.Id; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <long> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <UserDTO> UpdatePassword(UpdateUserDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; UserDTO result = null; try { var existingUser = _userRepository.Entities.Where(p => p.Username == model.Username).SingleOrDefault(); if (existingUser == null) { throw new Exception("Kullanıcı bulunamadı."); } existingUser.Password = model.Password; _unitOfWork.SaveChanges(); result = GetUser(existingUser.Id); serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <UserDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <bool> DeleteConversation(DeleteConversationDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; bool result = false; try { var existingConversation = _conversationRepository.GetById(model.ConversationId); if (existingConversation == null) { throw new Exception("Sohbet bilgisi bulunamadı."); } _conversationRepository.Delete(existingConversation); _unitOfWork.SaveChanges(); result = true; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <bool> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <List <ReportDTO> > GetReportList(ReportFilterDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; List <ReportDTO> result = null; try { Expression <Func <Contracts.Entities.EF.Report, bool> > expReport = p => true; if (model.YonDerId != null) { expReport = expReport.And(p => p.YonDerId == model.YonDerId); } if (model.ScholarshipHolderId != null) { expReport = expReport.And(p => p.ScholarshipHolderId == model.ScholarshipHolderId); } if (!string.IsNullOrEmpty(model.Subject)) { expReport = expReport.And(p => p.Subject.Contains(model.Subject)); } if (model.ReportDate != null) { expReport = expReport.And(p => p.ReportDate == model.ReportDate); } if (!string.IsNullOrEmpty(model.ReportText)) { expReport = expReport.And(p => p.Subject.Contains(model.ReportText)); } var reportList = _reportRepository.Entities.Where(expReport).ToList(); result = reportList.Select(p => new ReportDTO { Id = p.Id, YonDerId = p.YonDerId, YonDerName = $"{p.YonDer.FirstName} {p.YonDer.LastName}", ScholarshipHolderId = p.ScholarshipHolderId, ScholarshipHolderName = $"{p.ScholarshipHolder.FirstName} {p.ScholarshipHolder.LastName}", Subject = p.Subject, ReportDate = p.ReportDate, ReportText = p.ReportText, }).ToList(); serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <List <ReportDTO> > { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <long> CreateNewReport(CreateNewReportDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; long result = -1; try { var newReport = new Contracts.Entities.EF.Report { YonDerId = model.YonDerId, ScholarshipHolderId = model.ScholarshipHolderId, Subject = model.Subject, ReportDate = model.ReportDate, ReportText = model.ReportText }; var reportResult = _reportRepository.Add(newReport); _unitOfWork.SaveChanges(); result = reportResult.Id; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <long> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <long> CreateNewDonator(CreateNewDonatorDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; long result = -1; try { var anyExistingUser = _userRepository.Entities.Any(p => p.Username == model.Username && p.Email == model.Email && p.IsActive); if (anyExistingUser) { throw new Exception("Kullanıcı bilgisi mevcut."); } var newUser = new Contracts.Entities.EF.User { IsActive = true, Password = model.Password, Username = model.Username, UserTypeId = model.UserTypeId, Email = model.Email }; var newDonator = new Donator { FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate, OccupationId = model.OccupationId, PhoneNumber = model.PhoneNum, WorkPlace = model.WorkPlace, }; newUser.Donator.Add(newDonator); var userResult = _userRepository.Add(newUser); _unitOfWork.SaveChanges(); result = userResult.Id; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <long> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <ReportDTO> GetReport(long reportId) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; ReportDTO result = null; try { var existingReport = _reportRepository.Entities.Where(p => p.Id == reportId).SingleOrDefault(); if (existingReport == null) { throw new Exception("Rapor bulunamadı."); } //if (existingReport.YonDer == null) // throw new Exception("Rapora ait YönDer bilgisi bulunamadı."); //if (existingReport.ScholarshipHolder == null) // throw new Exception("Rapora ait bursiyer bilgisi bulunamadı."); result = new ReportDTO { Id = existingReport.Id, YonDerId = existingReport.YonDerId, YonDerName = $"{existingReport.YonDer.FirstName} {existingReport.YonDer.LastName}", ScholarshipHolderId = existingReport.ScholarshipHolderId, ScholarshipHolderName = $"{existingReport.ScholarshipHolder.FirstName} {existingReport.ScholarshipHolder.LastName}", Subject = existingReport.Subject, ReportDate = existingReport.ReportDate, ReportText = existingReport.ReportText }; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <ReportDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <UserDTO> UpdateProfile(UpdateUserDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; UserDTO result = null; try { var existingUser = _userRepository.Entities.Where(p => p.Id == model.UserId && p.IsActive).SingleOrDefault(); if (existingUser == null) { throw new Exception("Kullanıcı bulunamadı."); } if (existingUser.UserTypeId == (int)EnumUserType.NGOHead) { if (!existingUser.NgoHead.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingNgoHead = existingUser.NgoHead.Single(); existingNgoHead.FirstName = model.FirstName; existingNgoHead.LastName = model.LastName; existingNgoHead.BirthDate = model.BirthDate; existingNgoHead.PhoneNumber = model.PhoneNum; existingNgoHead.DutyStartDate = model.DutyStartDate; existingNgoHead.DutyEndDate = model.DutyEndDate; } if (existingUser.UserTypeId == (int)EnumUserType.ProjectManager) { if (!existingUser.ProjectManager.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingProjectManager = existingUser.ProjectManager.Single(); existingProjectManager.FirstName = model.FirstName; existingProjectManager.LastName = model.LastName; existingProjectManager.BirthDate = model.BirthDate; existingProjectManager.PhoneNumber = model.PhoneNum; existingProjectManager.DutyStartDate = model.DutyStartDate; existingProjectManager.DutyEndDate = model.DutyEndDate; } if (existingUser.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (!existingUser.ScholarshipCommittee.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingScholarshipCommittee = existingUser.ScholarshipCommittee.Single(); existingScholarshipCommittee.Title = model.Title; existingScholarshipCommittee.FirstName = model.FirstName; existingScholarshipCommittee.LastName = model.LastName; existingScholarshipCommittee.BirthDate = model.BirthDate; existingScholarshipCommittee.PhoneNumber = model.PhoneNum; existingScholarshipCommittee.DutyStartDate = model.DutyStartDate; existingScholarshipCommittee.DutyEndDate = model.DutyEndDate; } if (existingUser.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (!existingUser.ScholarshipHolder.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingScholarshipHolder = existingUser.ScholarshipHolder.Single(); existingScholarshipHolder.FirstName = model.FirstName; existingScholarshipHolder.LastName = model.LastName; existingScholarshipHolder.BirthDate = model.BirthDate; existingScholarshipHolder.PhoneNumber = model.PhoneNum; ///TODO:EKleme yapılacak } if (existingUser.UserTypeId == (int)EnumUserType.Donator) { if (!existingUser.Donator.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingDonator = existingUser.Donator.Single(); existingDonator.FirstName = model.FirstName; existingDonator.LastName = model.LastName; existingDonator.BirthDate = model.BirthDate; existingDonator.PhoneNumber = model.PhoneNum; //existingDonator.Occupation = model.Occupation; existingDonator.WorkPlace = model.WorkPlace; } if (existingUser.UserTypeId == (int)EnumUserType.Schoolmaster) { if (!existingUser.Schoolmaster.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingSchoolmaster = existingUser.Schoolmaster.Single(); existingSchoolmaster.FirstName = model.FirstName; existingSchoolmaster.LastName = model.LastName; existingSchoolmaster.BirthDate = model.BirthDate; existingSchoolmaster.PhoneNumber = model.PhoneNum; existingSchoolmaster.School = model.School; existingSchoolmaster.CityId = model.CityId; existingSchoolmaster.TownId = model.TownId; } if (existingUser.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (!existingUser.HostSchoolTeacher.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingHostSchoolTeacher = existingUser.HostSchoolTeacher.Single(); existingHostSchoolTeacher.FirstName = model.FirstName; existingHostSchoolTeacher.LastName = model.LastName; existingHostSchoolTeacher.BirthDate = model.BirthDate; existingHostSchoolTeacher.PhoneNumber = model.PhoneNum; // existingHostSchoolTeacher.School = model.School; // existingHostSchoolTeacher.Branch = model.Branch; } if (existingUser.UserTypeId == (int)EnumUserType.Student) { if (!existingUser.Student.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingStudent = existingUser.Student.Single(); existingStudent.FirstName = model.FirstName; existingStudent.LastName = model.LastName; existingStudent.BirthDate = model.BirthDate; existingStudent.PhoneNumber = model.PhoneNum; //existingStudent.School = model.School; existingStudent.EducationLevel = model.EducationLevel; existingStudent.Class = model.Class; } if (existingUser.UserTypeId == (int)EnumUserType.Volunteer) { if (!existingUser.Volunteer.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingVolunteer = existingUser.Volunteer.Single(); existingVolunteer.FirstName = model.FirstName; existingVolunteer.LastName = model.LastName; existingVolunteer.BirthDate = model.BirthDate; existingVolunteer.PhoneNumber = model.PhoneNum; existingVolunteer.IsStudent = model.Volunteer_IsStudent; existingVolunteer.UniversityId = null; existingVolunteer.DepartmentId = null; existingVolunteer.Class = null; existingVolunteer.OccupationId = null; if (model.Volunteer_IsStudent == true) { existingVolunteer.UniversityId = model.Volunteer_UniversityId; existingVolunteer.DepartmentId = model.Volunteer_DepartmentId; existingVolunteer.Class = model.Volunteer_Class; } else { existingVolunteer.OccupationId = model.Volunteer_OccupationId; } } if (existingUser.UserTypeId == (int)EnumUserType.YonDer) { if (!existingUser.YonDer.Any()) { throw new Exception("Kullanıcı bulunamadı."); } var existingYonDer = existingUser.YonDer.Single(); existingYonDer.FirstName = model.FirstName; existingYonDer.LastName = model.LastName; existingYonDer.BirthDate = model.BirthDate; existingYonDer.PhoneNumber = model.PhoneNum; existingYonDer.DutyStartDate = model.DutyStartDate; existingYonDer.DutyEndDate = model.DutyEndDate; } _unitOfWork.SaveChanges(); result = GetUser(model.UserId); serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <UserDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <List <ConversationDTO> > GetConversationList(long currentUserId, long userId) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; List <ConversationDTO> result = null; try { var selectedUser = _userRepository.GetById(userId); if (selectedUser == null) { throw new Exception("Kullanıcı bulunamadı."); } var conversationList = _conversationRepository.Entities.Where(p => (p.SenderId == currentUserId && p.ReceiverId == userId) || (p.SenderId == userId && p.ReceiverId == currentUserId)).ToList().OrderBy(o => o.Date).ToList(); result = new List <ConversationDTO>(); foreach (var conversation in conversationList) { var newConversation = new ConversationDTO(); #region selectedUserFullName string selectedUserFullName = string.Empty; if (selectedUser.UserTypeId == (int)EnumUserType.NGOHead) { if (selectedUser.NgoHead.Any()) { selectedUserFullName = $"{selectedUser.NgoHead.Single().FirstName} {selectedUser.NgoHead.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.ProjectManager) { if (selectedUser.ProjectManager.Any()) { selectedUserFullName = $"{selectedUser.ProjectManager.Single().FirstName} {selectedUser.ProjectManager.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (selectedUser.ScholarshipCommittee.Any()) { selectedUserFullName = $"{selectedUser.ScholarshipCommittee.Single().FirstName} {selectedUser.ScholarshipCommittee.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (selectedUser.ScholarshipHolder.Any()) { selectedUserFullName = $"{selectedUser.ScholarshipHolder.Single().FirstName} {selectedUser.ScholarshipHolder.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.Donator) { if (selectedUser.Donator.Any()) { selectedUserFullName = $"{selectedUser.Donator.Single().FirstName} {selectedUser.Donator.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.Schoolmaster) { if (selectedUser.Schoolmaster.Any()) { selectedUserFullName = $"{selectedUser.Schoolmaster.Single().FirstName} {selectedUser.Schoolmaster.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (selectedUser.HostSchoolTeacher.Any()) { selectedUserFullName = $"{selectedUser.HostSchoolTeacher.Single().FirstName} {selectedUser.HostSchoolTeacher.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.Student) { if (selectedUser.Student.Any()) { selectedUserFullName = $"{selectedUser.Student.Single().FirstName} {selectedUser.Student.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.Volunteer) { if (selectedUser.Volunteer.Any()) { selectedUserFullName = $"{selectedUser.Volunteer.Single().FirstName} {selectedUser.Volunteer.Single().LastName}"; } } if (selectedUser.UserTypeId == (int)EnumUserType.YonDer) { if (selectedUser.YonDer.Any()) { selectedUserFullName = $"{selectedUser.YonDer.Single().FirstName} {selectedUser.YonDer.Single().LastName}"; } } #endregion if (conversation.SenderId == currentUserId) { newConversation.MessageTypeId = (int)EnumMessageType.Gonderilen; } else { newConversation.MessageTypeId = (int)EnumMessageType.Gelen; } newConversation.Id = conversation.Id; newConversation.SenderId = conversation.SenderId; newConversation.ReceiverId = conversation.ReceiverId; newConversation.UserFullName = selectedUserFullName; newConversation.Message = conversation.Message; newConversation.Date = conversation.Date; result.Add(newConversation); } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <List <ConversationDTO> > { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <ProjectManagerBadgeDTO> GetProjectManagerBadge(long projectManagerId) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; ProjectManagerBadgeDTO result = null; try { result = new ProjectManagerBadgeDTO { ProjectExperienceBadgeList = new List <ProjectExperienceBadgeDTO>() }; var currentProjectManager = _projectManagerRepository.GetById(projectManagerId); if (currentProjectManager == null) { throw new Exception("Proje yöneticisi bilgisi bulunamadı."); } var projectDetailIdList = _projectDetailRepository.Entities.Where(p => p.StatusId == (int)EnumProjectSubDetailStatusType.Tamamlandi).Select(s => s.Id).Distinct().ToList(); var filteredProjectDetailVoteList = _projectDetailVoteRepository.Entities.Where(p => projectDetailIdList.Contains(p.ProjectDetailId)).ToList(); var averageProjectVote = filteredProjectDetailVoteList.Average(p => p.Vote); //tüm ortalama var groupedprojectDetailVoteList = filteredProjectDetailVoteList.GroupBy(g => new { g.ProjectDetailId }).ToList(); int badgeVote = 3; long projectDetailId = -1; int badgeCount = 0; foreach (var projectDetailVote in groupedprojectDetailVoteList) { int totalVoteProjectDetail = projectDetailVote.Sum(s => s.Vote); var averageProjectDetailVote = projectDetailVote.Average(p => p.Vote); // detay bazında ortalama if (averageProjectDetailVote > badgeVote) { projectDetailId = projectDetailVote.Key.ProjectDetailId; var bestProjectDetail = _projectDetailRepository.GetById(projectDetailId); if (bestProjectDetail != null) { if (bestProjectDetail.Project.ProjectManagerId == projectManagerId) { result.IsHighestVoteBadge = true; } var projectManagerProjectDetailExperienceList = _projectDetailRepository.Entities.Where(p => p.Project.ProjectManagerId == projectManagerId && p.StatusId == (int)EnumProjectSubDetailStatusType.Tamamlandi).ToList(); foreach (var projectDetail in projectManagerProjectDetailExperienceList) { string projectDetailName = $"Proje: {projectDetail.Project.Name} ({projectDetail.StartDate.ToString("dd/MM/yyyy")}-{projectDetail.EndDate.ToString("dd/MM/yyyy")})"; var randomHexColor = CreateRandomHexColor(); result.ProjectExperienceBadgeList.Add(new ProjectExperienceBadgeDTO { ProjectDetailId = projectDetailId, ProjectDetailName = projectDetailName, BadgeColor = randomHexColor }); } } } } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <ProjectManagerBadgeDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <VolunteerBadgeDTO> GetVolunteerBadge(long volunteerId) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; VolunteerBadgeDTO result = null; try { result = new VolunteerBadgeDTO { ActivityLeadershipBadgeList = new List <ActivityLeadershipBadgeDTO>(), GeniusBadgeList = new List <GeniusBadgeDTO>() }; var currentVolunteer = _volunteerRepository.GetById(volunteerId); if (currentVolunteer == null) { throw new Exception("Gönüllü bilgisi bulunamadı."); } var currentVolunteerProjectDetailIdList = _projectDetailActivityRepository.Entities.Where(p => p.VolunteerId == currentVolunteer.Id && p.StatusId == (int)EnumActivityStatusType.Onaylandi).Select(s => s.ProjectDetailId).Distinct().ToList(); var filteredProjectDetailActivityList = _projectDetailActivityRepository.Entities.Where(p => currentVolunteerProjectDetailIdList.Contains(p.ProjectDetailId) && p.StatusId == (int)EnumActivityStatusType.Onaylandi).ToList(); var groupedFilteredProjectDetailActivityList = filteredProjectDetailActivityList.GroupBy(g => new { g.ProjectDetailId, g.ActivityId, }).ToList(); foreach (var projectDetailActivity in groupedFilteredProjectDetailActivityList) { var projectDetailId = projectDetailActivity.Key.ProjectDetailId; var activityId = projectDetailActivity.Key.ActivityId; var currentActivity = _activityRepository.GetById(activityId); var volunteerVoteList = _volunteerVoteRepository.Entities.Where(p => p.ProjectDetailId == projectDetailId && p.ActivityId == activityId).ToList(); if (volunteerVoteList != null) { var maxVoteByVolunteer = volunteerVoteList.Max(m => m.Vote); var volunteerVoteTotalList = volunteerVoteList.Where(p => p.VolunteerId == currentVolunteer.Id).ToList(); var volunteerVote = volunteerVoteTotalList.Average(p => p.Vote); if (volunteerVote != 0) { if (volunteerVote >= maxVoteByVolunteer) { string projectDetailName = $"Proje: {_projectDetailRepository.GetById(projectDetailId).Project.Name} ({_projectDetailRepository.GetById(projectDetailId).StartDate.ToString("dd/MM/yyyy")}-{_projectDetailRepository.GetById(projectDetailId).EndDate.ToString("dd/MM/yyyy")}) Aktivite: {currentActivity.Name}"; var randomHexColor = CreateRandomHexColor(); result.ActivityLeadershipBadgeList.Add(new ActivityLeadershipBadgeDTO { ProjectDetailId = projectDetailId, ProjectDetailName = projectDetailName, BadgeColor = randomHexColor }); } if (volunteerVote >= 4) { string activityName = currentActivity.Name; var randomHexColor = CreateRandomHexColor(); result.GeniusBadgeList.Add(new GeniusBadgeDTO { ActivityId = activityId, ActivityName = activityName, BadgeColor = randomHexColor }); } } } } if (result.ActivityLeadershipBadgeList.Count >= 3 && result.ActivityLeadershipBadgeList.Count < 7) { result.IsBronzeActivityLeadershipBadge = true; } else if (result.ActivityLeadershipBadgeList.Count >= 7 && result.ActivityLeadershipBadgeList.Count < 12) { result.IsSilverActivityLeadershipBadge = true; } else if (result.ActivityLeadershipBadgeList.Count >= 12) { result.IsGoldActivityLeadershipBadge = true; } var VolunteerProjectDetailActivityList = _projectDetailActivityRepository.Entities.Where(p => p.StatusId == (int)EnumActivityStatusType.Onaylandi).GroupBy(v => v.VolunteerId).ToList(); var maxActivityJoined = VolunteerProjectDetailActivityList.Max(m => m.Count()); var currentvolunteerJoinedActivity = _projectDetailActivityRepository.Entities.Where(p => p.VolunteerId == currentVolunteer.Id && p.StatusId == (int)EnumActivityStatusType.Onaylandi).Count(); if (maxActivityJoined == currentvolunteerJoinedActivity) { result.IsBee = true; } else if (maxActivityJoined > currentvolunteerJoinedActivity) { result.NeededForBeeBadge = maxActivityJoined - currentvolunteerJoinedActivity; } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <VolunteerBadgeDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <long> CreateNewVolunteer(CreateNewVolunteerDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; long result = -1; try { var anyExistingUser = _userRepository.Entities.Any(p => p.Username == model.Username && p.Email == model.Email && p.IsActive); if (anyExistingUser) { throw new Exception("Kullanıcı bilgisi mevcut."); } var newUser = new Contracts.Entities.EF.User { IsActive = true, Password = model.Password, Username = model.Username, UserTypeId = model.UserTypeId, Email = model.Email }; var newVolunteer = new Volunteer { BirthDate = model.BirthDate, Class = model.Class, DepartmentId = model.DepartmentId, FirstName = model.FirstName, IsStudent = model.IsStudent, LastName = model.LastName, OccupationId = model.OccupationId, PhoneNumber = model.PhoneNum, UniversityId = model.UniversityId }; var newInterest1 = new InterestVolunteer { ActivityId = model.Interest1Id }; var newInterest2 = new InterestVolunteer { ActivityId = model.Interest2Id }; var newInterest3 = new InterestVolunteer { ActivityId = model.Interest3Id }; newUser.Volunteer.Add(newVolunteer); newVolunteer.InterestVolunteer.Add(newInterest1); newVolunteer.InterestVolunteer.Add(newInterest2); newVolunteer.InterestVolunteer.Add(newInterest3); var userResult = _userRepository.Add(newUser); _unitOfWork.SaveChanges(); result = userResult.Id; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <long> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <UserDTO> Login(string username, string password) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; UserDTO result = null; try { var user = _userRepository.Entities.Where(m => m.Username == username && m.Password == password).SingleOrDefault(); if (user == null) { errorMessage = "Girdiğiniz bilgiler hatalı! Lütfen kontrol edip tekrar deneyin."; throw new Exception(errorMessage); } result = new UserDTO() { UserId = user.Id, UserTypeId = user.UserTypeId, Username = user.Username, Password = user.Password, Email = user.Email, IsActive = user.IsActive }; //---NGO Head Info---// if (user.UserTypeId == (int)EnumUserType.NGOHead) { if (user.NgoHead.Any()) { var currentNgoHead = user.NgoHead.Single(); result.Id = currentNgoHead.Id; result.FirstName = currentNgoHead.FirstName; result.LastName = currentNgoHead.LastName; result.BirthDate = currentNgoHead.BirthDate; result.PhoneNum = currentNgoHead.PhoneNumber; result.DutyStartDate = currentNgoHead.DutyStartDate; result.DutyEndDate = currentNgoHead.DutyEndDate; } } //---Project Manager Info---// if (user.UserTypeId == (int)EnumUserType.ProjectManager) { if (user.ProjectManager.Any()) { var currentProjectManager = user.ProjectManager.Single(); result.Id = currentProjectManager.Id; result.FirstName = currentProjectManager.FirstName; result.LastName = currentProjectManager.LastName; result.BirthDate = currentProjectManager.BirthDate; result.PhoneNum = currentProjectManager.PhoneNumber; result.DutyStartDate = currentProjectManager.DutyStartDate; result.DutyEndDate = currentProjectManager.DutyEndDate; } } //---Scholarship Committee Info---// if (user.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (user.ScholarshipCommittee.Any()) { var currentScholarshipCommittee = user.ScholarshipCommittee.Single(); result.Id = currentScholarshipCommittee.Id; result.FirstName = currentScholarshipCommittee.FirstName; result.LastName = currentScholarshipCommittee.LastName; result.BirthDate = currentScholarshipCommittee.BirthDate; result.Title = currentScholarshipCommittee.Title; result.PhoneNum = currentScholarshipCommittee.PhoneNumber; result.DutyStartDate = currentScholarshipCommittee.DutyStartDate; result.DutyEndDate = currentScholarshipCommittee.DutyEndDate; } } //---Scholarship Holder Info---// if (user.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (user.ScholarshipHolder.Any()) { var currentScholarshipHolder = user.ScholarshipHolder.Single(); result.Id = currentScholarshipHolder.Id; result.FirstName = currentScholarshipHolder.FirstName; result.LastName = currentScholarshipHolder.LastName; if (currentScholarshipHolder.Donator != null) { result.DonatorName = $"{currentScholarshipHolder.Donator.FirstName} {currentScholarshipHolder.Donator.LastName}"; } if (currentScholarshipHolder.YonDer != null) { result.YonDerName = $"{currentScholarshipHolder.YonDer.FirstName} {currentScholarshipHolder.YonDer.LastName}"; } result.BirthDate = currentScholarshipHolder.BirthDate; result.PhoneNum = currentScholarshipHolder.PhoneNumber; result.ScholarshipStartDate = currentScholarshipHolder.ScholarshipStartDate; result.ScholarshipEndDate = currentScholarshipHolder.ScholarshipEndDate; result.ScholarshipAmount = currentScholarshipHolder.ScholarshipAmount; result.IbanNo = currentScholarshipHolder.IbanNo; #region EducationInfo result.EducationLevel = currentScholarshipHolder.EducationLevel; if (currentScholarshipHolder.School != null) { result.School = currentScholarshipHolder.School; } result.Class = currentScholarshipHolder.Class; result.CumGPA = currentScholarshipHolder.CumGPA; result.StudentDocument = currentScholarshipHolder.StudentDocument; result.Transcript = currentScholarshipHolder.Transcript; #endregion result.HealthConditionInfo = currentScholarshipHolder.HealthConditionInfo; result.MonthlyIncome = currentScholarshipHolder.MonthlyIncome; #region MotherInfo result.MotherName = currentScholarshipHolder.MotherName; if (currentScholarshipHolder.IsMotherWorking) { var occupation = _occupationRepository.GetById(currentScholarshipHolder.MotherOccupationId); if (occupation != null) { result.MotherOccupation = occupation.Name; } } #endregion #region FatherInfo result.FatherName = currentScholarshipHolder.FatherName; if (currentScholarshipHolder.IsFatherWorking) { var occupation = _occupationRepository.GetById(currentScholarshipHolder.FatherOccupationId); if (occupation != null) { result.FatherOccupation = occupation.Name; } } #endregion result.NumberOfSiblings = currentScholarshipHolder.NumberOfSiblings; } } //---Donator Info---// if (user.UserTypeId == (int)EnumUserType.Donator) { if (user.Donator.Any()) { var currentDonator = user.Donator.Single(); result.Id = currentDonator.Id; result.FirstName = currentDonator.FirstName; result.LastName = currentDonator.LastName; if (currentDonator.Occupation != null) { result.Occupation = currentDonator.Occupation.Name; } result.BirthDate = currentDonator.BirthDate; result.PhoneNum = currentDonator.PhoneNumber; result.WorkPlace = currentDonator.WorkPlace; } } //---Schoolmaster Info---// if (user.UserTypeId == (int)EnumUserType.Schoolmaster) { if (user.Schoolmaster.Any()) { var currentSchoolmaster = user.Schoolmaster.Single(); result.Id = currentSchoolmaster.Id; result.FirstName = currentSchoolmaster.FirstName; result.LastName = currentSchoolmaster.LastName; result.BirthDate = currentSchoolmaster.BirthDate; result.PhoneNum = currentSchoolmaster.PhoneNumber; if (currentSchoolmaster.School != null) { result.School = currentSchoolmaster.School; } } } //---Host School Teacher Info---// if (user.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (user.HostSchoolTeacher.Any()) { var currentHostSchoolTeacher = user.HostSchoolTeacher.Single(); result.Id = currentHostSchoolTeacher.Id; result.FirstName = currentHostSchoolTeacher.FirstName; result.LastName = currentHostSchoolTeacher.LastName; result.BirthDate = currentHostSchoolTeacher.BirthDate; result.PhoneNum = currentHostSchoolTeacher.PhoneNumber; if (currentHostSchoolTeacher.School != null) { result.School = currentHostSchoolTeacher.School; } if (currentHostSchoolTeacher.Branch != null) { result.Branch = currentHostSchoolTeacher.Branch.Name; } } } //---Student Info---// if (user.UserTypeId == (int)EnumUserType.Student) { if (user.Student.Any()) { var currentStudent = user.Student.Single(); result.Id = currentStudent.Id; result.FirstName = currentStudent.FirstName; result.LastName = currentStudent.LastName; result.BirthDate = currentStudent.BirthDate; result.PhoneNum = currentStudent.PhoneNumber; if (currentStudent.School != null) { result.School = currentStudent.School; } result.CumGPA = currentStudent.CumGPA; result.Class = currentStudent.Class; result.EducationLevel = currentStudent.EducationLevel; } } //---Volunteer Info---// if (user.UserTypeId == (int)EnumUserType.Volunteer) { if (user.Volunteer.Any()) { var currentVolunteer = user.Volunteer.Single(); result.Id = currentVolunteer.Id; result.FirstName = currentVolunteer.FirstName; result.LastName = currentVolunteer.LastName; result.BirthDate = currentVolunteer.BirthDate; result.PhoneNum = currentVolunteer.PhoneNumber; result.IsStudent = currentVolunteer.IsStudent; result.UniversityId = currentVolunteer.UniversityId; result.DepartmentId = currentVolunteer.DepartmentId; result.Class = currentVolunteer.Class; result.OccupationId = currentVolunteer.OccupationId; if (currentVolunteer.University != null) { result.University = currentVolunteer.University.Name; } if (currentVolunteer.Department != null) { result.Department = currentVolunteer.Department.Name; } if (currentVolunteer.Occupation != null) { result.Occupation = currentVolunteer.Occupation.Name; } } } //---Yön-Der Info---// if (user.UserTypeId == (int)EnumUserType.YonDer) { if (user.YonDer.Any()) { var currentYonDer = user.YonDer.Single(); result.Id = currentYonDer.Id; result.FirstName = currentYonDer.FirstName; result.LastName = currentYonDer.LastName; result.BirthDate = currentYonDer.BirthDate; result.PhoneNum = currentYonDer.PhoneNumber; result.DutyStartDate = currentYonDer.DutyStartDate; result.DutyEndDate = currentYonDer.DutyEndDate; } } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <UserDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <UserDTO> GetUser(long userId) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; UserDTO result = null; try { var existingUser = _userRepository.Entities.Where(p => p.Id == userId).SingleOrDefault(); if (existingUser == null) { throw new Exception("Kullanıcı bulunamadı."); } result = new UserDTO { UserId = existingUser.Id, UserTypeId = existingUser.UserTypeId, Username = existingUser.Username, Email = existingUser.Email, IsActive = existingUser.IsActive }; //---NGO Head Info---// if (existingUser.UserTypeId == (int)EnumUserType.NGOHead) { if (existingUser.NgoHead.Any()) { var selectedNgoHead = existingUser.NgoHead.Single(); result.Id = selectedNgoHead.Id; result.FirstName = selectedNgoHead.FirstName; result.LastName = selectedNgoHead.LastName; result.BirthDate = selectedNgoHead.BirthDate; result.PhoneNum = selectedNgoHead.PhoneNumber; result.DutyStartDate = selectedNgoHead.DutyStartDate; result.DutyEndDate = selectedNgoHead.DutyEndDate; } } //---ProjectManager Info---// if (existingUser.UserTypeId == (int)EnumUserType.ProjectManager) { if (existingUser.ProjectManager.Any()) { var selectedProjectManager = existingUser.ProjectManager.Single(); result.Id = selectedProjectManager.Id; result.FirstName = selectedProjectManager.FirstName; result.LastName = selectedProjectManager.LastName; result.BirthDate = selectedProjectManager.BirthDate; result.PhoneNum = selectedProjectManager.PhoneNumber; result.DutyStartDate = selectedProjectManager.DutyStartDate; result.DutyEndDate = selectedProjectManager.DutyEndDate; } } //---ScholarshipCommittee Info---// if (existingUser.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (existingUser.ScholarshipCommittee.Any()) { var selectedScholarshipCommittee = existingUser.ScholarshipCommittee.Single(); result.Id = selectedScholarshipCommittee.Id; result.Title = selectedScholarshipCommittee.Title; result.FirstName = selectedScholarshipCommittee.FirstName; result.LastName = selectedScholarshipCommittee.LastName; result.BirthDate = selectedScholarshipCommittee.BirthDate; result.PhoneNum = selectedScholarshipCommittee.PhoneNumber; result.DutyStartDate = selectedScholarshipCommittee.DutyStartDate; result.DutyEndDate = selectedScholarshipCommittee.DutyEndDate; } } //---ScholarshipHolder Info---// if (existingUser.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (existingUser.ScholarshipHolder.Any()) { var selectedScholarshipHolder = existingUser.ScholarshipHolder.Single(); result.Id = selectedScholarshipHolder.Id; result.YonDerName = selectedScholarshipHolder.YonDerId.ToString(); result.FirstName = selectedScholarshipHolder.FirstName; result.LastName = selectedScholarshipHolder.LastName; result.BirthDate = selectedScholarshipHolder.BirthDate; result.PhoneNum = selectedScholarshipHolder.PhoneNumber; result.ScholarshipStartDate = selectedScholarshipHolder.ScholarshipStartDate; result.ScholarshipEndDate = selectedScholarshipHolder.ScholarshipEndDate; result.ScholarshipAmount = selectedScholarshipHolder.ScholarshipAmount; result.IbanNo = selectedScholarshipHolder.IbanNo; result.School = selectedScholarshipHolder.School.ToString(); result.EducationLevel = selectedScholarshipHolder.EducationLevel; result.Class = selectedScholarshipHolder.Class.ToString(); result.CumGPA = selectedScholarshipHolder.CumGPA; result.MotherName = selectedScholarshipHolder.MotherName; result.MotherOccupation = selectedScholarshipHolder.MotherOccupationId.ToString(); result.FatherName = selectedScholarshipHolder.FatherName; result.FatherOccupation = selectedScholarshipHolder.FatherOccupationId.ToString(); result.NumberOfSiblings = selectedScholarshipHolder.NumberOfSiblings; //result.SiblingFirstName = //result.SiblingLastName = selectedScholarshipHolder. //result.SiblingMonthlyIncome = selectedScholarshipHolder. //result.SiblingOccupation = selectedScholarshipHolder. result.MonthlyIncome = selectedScholarshipHolder.MonthlyIncome; result.HealthConditionInfo = selectedScholarshipHolder.HealthConditionInfo; } } //---Donator Info---// if (existingUser.UserTypeId == (int)EnumUserType.Donator) { if (existingUser.Donator.Any()) { var selectedDonator = existingUser.Donator.Single(); result.Id = selectedDonator.Id; result.FirstName = selectedDonator.FirstName; result.LastName = selectedDonator.LastName; result.BirthDate = selectedDonator.BirthDate; result.PhoneNum = selectedDonator.PhoneNumber; result.Occupation = selectedDonator.OccupationId.ToString(); result.WorkPlace = selectedDonator.WorkPlace; } } //---Schoolmaster Info---// if (existingUser.UserTypeId == (int)EnumUserType.Schoolmaster) { if (existingUser.Schoolmaster.Any()) { var selectedSchoolmaster = existingUser.Schoolmaster.Single(); result.Id = selectedSchoolmaster.Id; result.FirstName = selectedSchoolmaster.FirstName; result.LastName = selectedSchoolmaster.LastName; result.BirthDate = selectedSchoolmaster.BirthDate; result.PhoneNum = selectedSchoolmaster.PhoneNumber; result.CityId = selectedSchoolmaster.CityId; result.TownId = selectedSchoolmaster.TownId; result.School = selectedSchoolmaster.School; } } //---HostSchoolTeacher Info---// if (existingUser.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (existingUser.HostSchoolTeacher.Any()) { var selectedHostSchoolTeacher = existingUser.HostSchoolTeacher.Single(); result.Id = selectedHostSchoolTeacher.Id; result.FirstName = selectedHostSchoolTeacher.FirstName; result.LastName = selectedHostSchoolTeacher.LastName; result.BirthDate = selectedHostSchoolTeacher.BirthDate; result.PhoneNum = selectedHostSchoolTeacher.PhoneNumber; //result.City = //result.Town = result.School = selectedHostSchoolTeacher.School; result.Branch = selectedHostSchoolTeacher.BranchId.ToString(); } } //---Student Info---// if (existingUser.UserTypeId == (int)EnumUserType.Student) { if (existingUser.Student.Any()) { var selectedStudent = existingUser.Student.Single(); result.Id = selectedStudent.Id; result.FirstName = selectedStudent.FirstName; result.LastName = selectedStudent.LastName; result.BirthDate = selectedStudent.BirthDate; result.PhoneNum = selectedStudent.PhoneNumber; //result = //result = result.School = selectedStudent.SchoolId.ToString(); result.EducationLevel = selectedStudent.EducationLevel; result.Class = selectedStudent.Class; result.CumGPA = selectedStudent.CumGPA; } } //---Volunteer Info---// if (existingUser.UserTypeId == (int)EnumUserType.Volunteer) { if (existingUser.Volunteer.Any()) { var selectedVolunteer = existingUser.Volunteer.Single(); result.Id = selectedVolunteer.Id; result.FirstName = selectedVolunteer.FirstName; result.LastName = selectedVolunteer.LastName; result.BirthDate = selectedVolunteer.BirthDate; result.PhoneNum = selectedVolunteer.PhoneNumber; result.IsStudent = selectedVolunteer.IsStudent; result.University = selectedVolunteer.UniversityId.ToString(); result.Department = selectedVolunteer.DepartmentId.ToString(); result.Class = selectedVolunteer.Class; result.Occupation = selectedVolunteer.OccupationId.ToString(); } } //---YonDer Info---// if (existingUser.UserTypeId == (int)EnumUserType.YonDer) { if (existingUser.YonDer.Any()) { var selectedYonDer = existingUser.YonDer.Single(); result.Id = selectedYonDer.Id; result.FirstName = selectedYonDer.FirstName; result.LastName = selectedYonDer.LastName; result.BirthDate = selectedYonDer.BirthDate; result.PhoneNum = selectedYonDer.PhoneNumber; result.DutyStartDate = selectedYonDer.DutyStartDate; result.DutyEndDate = selectedYonDer.DutyEndDate; } } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <UserDTO> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <List <UserDTO> > GetUserList() { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; List <UserDTO> result = null; try { var userList = _userRepository.Entities.Where(p => p.IsActive == true).ToList(); result = new List <UserDTO>(); foreach (var user in userList) { var newUser = new UserDTO(); newUser.UserId = user.Id; newUser.UserTypeId = user.UserTypeId; newUser.UserType = EnumHelper.GetEnumDescription(typeof(EnumUserType), user.UserTypeId.ToString()); newUser.Username = user.Username; newUser.Email = user.Email; newUser.IsActive = user.IsActive; if (user.UserTypeId == (int)EnumUserType.NGOHead) { if (user.NgoHead.Any()) { newUser.Id = user.NgoHead.Single().Id; newUser.FirstName = user.NgoHead.Single().FirstName; newUser.LastName = user.NgoHead.Single().LastName; newUser.BirthDate = user.NgoHead.Single().BirthDate; newUser.PhoneNum = user.NgoHead.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ProjectManager) { if (user.ProjectManager.Any()) { newUser.Id = user.ProjectManager.Single().Id; newUser.FirstName = user.ProjectManager.Single().FirstName; newUser.LastName = user.ProjectManager.Single().LastName; newUser.BirthDate = user.ProjectManager.Single().BirthDate; newUser.PhoneNum = user.ProjectManager.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (user.ScholarshipCommittee.Any()) { newUser.Id = user.ScholarshipCommittee.Single().Id; newUser.FirstName = user.ScholarshipCommittee.Single().FirstName; newUser.LastName = user.ScholarshipCommittee.Single().LastName; newUser.BirthDate = user.ScholarshipCommittee.Single().BirthDate; newUser.PhoneNum = user.ScholarshipCommittee.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (user.ScholarshipHolder.Any()) { newUser.Id = user.ScholarshipHolder.Single().Id; newUser.FirstName = user.ScholarshipHolder.Single().FirstName; newUser.LastName = user.ScholarshipHolder.Single().LastName; newUser.BirthDate = user.ScholarshipHolder.Single().BirthDate; newUser.PhoneNum = user.ScholarshipHolder.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Donator) { if (user.Donator.Any()) { newUser.Id = user.Donator.Single().Id; newUser.FirstName = user.Donator.Single().FirstName; newUser.LastName = user.Donator.Single().LastName; newUser.BirthDate = user.Donator.Single().BirthDate; newUser.PhoneNum = user.Donator.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Schoolmaster) { if (user.Schoolmaster.Any()) { newUser.Id = user.Schoolmaster.Single().Id; newUser.FirstName = user.Schoolmaster.Single().FirstName; newUser.LastName = user.Schoolmaster.Single().LastName; newUser.BirthDate = user.Schoolmaster.Single().BirthDate; newUser.PhoneNum = user.Schoolmaster.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (user.HostSchoolTeacher.Any()) { newUser.Id = user.HostSchoolTeacher.Single().Id; newUser.FirstName = user.HostSchoolTeacher.Single().FirstName; newUser.LastName = user.HostSchoolTeacher.Single().LastName; newUser.BirthDate = user.HostSchoolTeacher.Single().BirthDate; newUser.PhoneNum = user.HostSchoolTeacher.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Student) { if (user.Student.Any()) { newUser.Id = user.Student.Single().Id; newUser.FirstName = user.Student.Single().FirstName; newUser.LastName = user.Student.Single().LastName; newUser.BirthDate = user.Student.Single().BirthDate; newUser.PhoneNum = user.Student.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Volunteer) { if (user.Volunteer.Any()) { newUser.Id = user.Volunteer.Single().Id; newUser.FirstName = user.Volunteer.Single().FirstName; newUser.LastName = user.Volunteer.Single().LastName; newUser.BirthDate = user.Volunteer.Single().BirthDate; newUser.PhoneNum = user.Volunteer.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.YonDer) { if (user.YonDer.Any()) { newUser.Id = user.YonDer.Single().Id; newUser.FirstName = user.YonDer.Single().FirstName; newUser.LastName = user.YonDer.Single().LastName; newUser.BirthDate = user.YonDer.Single().BirthDate; newUser.PhoneNum = user.YonDer.Single().PhoneNumber; } } result.Add(newUser); } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <List <UserDTO> > { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }
public ServiceResult <List <UserDTO> > GetUserList(UserFilterDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; List <UserDTO> result = null; try { Expression <Func <Contracts.Entities.EF.User, bool> > expUser = p => true; #region availableUserTypeIdList List <int> availableUserTypeIdList = new List <int>(); if (model.CurrentUserTypeId == (int)EnumUserType.NGOHead) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ProjectManager); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipCommittee); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipHolder); availableUserTypeIdList.Add((int)EnumUserType.Donator); availableUserTypeIdList.Add((int)EnumUserType.Schoolmaster); availableUserTypeIdList.Add((int)EnumUserType.HostSchoolTeacher); availableUserTypeIdList.Add((int)EnumUserType.Student); availableUserTypeIdList.Add((int)EnumUserType.Volunteer); availableUserTypeIdList.Add((int)EnumUserType.YonDer); } if (model.CurrentUserTypeId == (int)EnumUserType.ProjectManager) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ProjectManager); availableUserTypeIdList.Add((int)EnumUserType.Schoolmaster); availableUserTypeIdList.Add((int)EnumUserType.HostSchoolTeacher); availableUserTypeIdList.Add((int)EnumUserType.Student); availableUserTypeIdList.Add((int)EnumUserType.Volunteer); } if (model.CurrentUserTypeId == (int)EnumUserType.ScholarshipCommittee) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipCommittee); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipHolder); availableUserTypeIdList.Add((int)EnumUserType.Donator); availableUserTypeIdList.Add((int)EnumUserType.YonDer); } if (model.CurrentUserTypeId == (int)EnumUserType.ScholarshipHolder) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipCommittee); availableUserTypeIdList.Add((int)EnumUserType.YonDer); } if (model.CurrentUserTypeId == (int)EnumUserType.Donator) { } if (model.CurrentUserTypeId == (int)EnumUserType.Schoolmaster) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.HostSchoolTeacher); availableUserTypeIdList.Add((int)EnumUserType.Student); } if (model.CurrentUserTypeId == (int)EnumUserType.HostSchoolTeacher) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.Schoolmaster); availableUserTypeIdList.Add((int)EnumUserType.HostSchoolTeacher); availableUserTypeIdList.Add((int)EnumUserType.Student); } if (model.CurrentUserTypeId == (int)EnumUserType.Student) { } if (model.CurrentUserTypeId == (int)EnumUserType.Volunteer) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ProjectManager); } if (model.CurrentUserTypeId == (int)EnumUserType.YonDer) { availableUserTypeIdList.Add((int)EnumUserType.NGOHead); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipCommittee); availableUserTypeIdList.Add((int)EnumUserType.ScholarshipHolder); availableUserTypeIdList.Add((int)EnumUserType.Donator); } expUser = expUser.And(p => availableUserTypeIdList.Contains(p.UserTypeId)); #endregion if (model.UserTypeId != null) { expUser = expUser.And(p => p.UserTypeId == model.UserTypeId.Value); } if (!string.IsNullOrEmpty(model.UserName)) { expUser = expUser.And(p => p.Username.Contains(model.UserName)); } if (model.Status != null) { if (model.Status == (int)EnumUserStatus.Aktif) { expUser = expUser.And(p => p.IsActive == true); } else if (model.Status == (int)EnumUserStatus.Pasif) { expUser = expUser.And(p => p.IsActive == false); } } if (!string.IsNullOrEmpty(model.Email)) { expUser = expUser.And(p => p.Email.Contains(model.Email)); } if (!string.IsNullOrEmpty(model.FirstName)) { expUser = expUser.And(p => p.NgoHead.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.ProjectManager.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.ScholarshipCommittee.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.ScholarshipHolder.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.Donator.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.Schoolmaster.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.HostSchoolTeacher.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.Student.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.Volunteer.Any(p2 => p2.FirstName.Contains(model.FirstName)) || p.YonDer.Any(p2 => p2.FirstName.Contains(model.FirstName)) ); } if (!string.IsNullOrEmpty(model.LastName)) { expUser = expUser.And(p => p.NgoHead.Any(p2 => p2.LastName.Contains(model.LastName)) || p.ProjectManager.Any(p2 => p2.LastName.Contains(model.LastName)) || p.ScholarshipCommittee.Any(p2 => p2.LastName.Contains(model.LastName)) || p.ScholarshipHolder.Any(p2 => p2.LastName.Contains(model.LastName)) || p.Donator.Any(p2 => p2.LastName.Contains(model.LastName)) || p.Schoolmaster.Any(p2 => p2.LastName.Contains(model.LastName)) || p.HostSchoolTeacher.Any(p2 => p2.LastName.Contains(model.LastName)) || p.Student.Any(p2 => p2.LastName.Contains(model.LastName)) || p.Volunteer.Any(p2 => p2.LastName.Contains(model.LastName)) || p.YonDer.Any(p2 => p2.LastName.Contains(model.LastName)) ); } if (!string.IsNullOrEmpty(model.Phone)) { expUser = expUser.And(p => p.NgoHead.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.ProjectManager.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.ScholarshipCommittee.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.ScholarshipHolder.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.Donator.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.Schoolmaster.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.HostSchoolTeacher.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.Student.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.Volunteer.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) || p.YonDer.Any(p2 => p2.PhoneNumber.Contains(model.Phone)) ); } if (model.BirthDate != null) { expUser = expUser.And(p => p.NgoHead.Any(p2 => p2.BirthDate == model.BirthDate) || p.ProjectManager.Any(p2 => p2.BirthDate == model.BirthDate) || p.ScholarshipCommittee.Any(p2 => p2.BirthDate == model.BirthDate) || p.ScholarshipHolder.Any(p2 => p2.BirthDate == model.BirthDate) || p.Donator.Any(p2 => p2.BirthDate == model.BirthDate) || p.Schoolmaster.Any(p2 => p2.BirthDate == model.BirthDate) || p.HostSchoolTeacher.Any(p2 => p2.BirthDate == model.BirthDate) || p.Student.Any(p2 => p2.BirthDate == model.BirthDate) || p.Volunteer.Any(p2 => p2.BirthDate == model.BirthDate) || p.YonDer.Any(p2 => p2.BirthDate == model.BirthDate) ); } var userList = _userRepository.Entities.Where(expUser).ToList(); result = new List <UserDTO>(); foreach (var user in userList) { var newUser = new UserDTO(); newUser.UserId = user.Id; newUser.UserTypeId = user.UserTypeId; newUser.UserType = EnumHelper.GetEnumDescription(typeof(EnumUserType), user.UserTypeId.ToString()); newUser.Username = user.Username; newUser.Email = user.Email; newUser.IsActive = user.IsActive; if (user.IsActive) { newUser.UserStatus = EnumHelper.GetEnumDescription(typeof(EnumUserStatus), ((int)EnumUserStatus.Aktif).ToString()); } else { newUser.UserStatus = EnumHelper.GetEnumDescription(typeof(EnumUserStatus), ((int)EnumUserStatus.Pasif).ToString()); } if (user.UserTypeId == (int)EnumUserType.NGOHead) { if (user.NgoHead.Any()) { newUser.Id = user.NgoHead.Single().Id; newUser.FirstName = user.NgoHead.Single().FirstName; newUser.LastName = user.NgoHead.Single().LastName; newUser.BirthDate = user.NgoHead.Single().BirthDate; newUser.PhoneNum = user.NgoHead.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ProjectManager) { if (user.ProjectManager.Any()) { newUser.Id = user.ProjectManager.Single().Id; newUser.FirstName = user.ProjectManager.Single().FirstName; newUser.LastName = user.ProjectManager.Single().LastName; newUser.BirthDate = user.ProjectManager.Single().BirthDate; newUser.PhoneNum = user.ProjectManager.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ScholarshipCommittee) { if (user.ScholarshipCommittee.Any()) { newUser.Id = user.ScholarshipCommittee.Single().Id; newUser.FirstName = user.ScholarshipCommittee.Single().FirstName; newUser.LastName = user.ScholarshipCommittee.Single().LastName; newUser.BirthDate = user.ScholarshipCommittee.Single().BirthDate; newUser.PhoneNum = user.ScholarshipCommittee.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.ScholarshipHolder) { if (user.ScholarshipHolder.Any()) { newUser.Id = user.ScholarshipHolder.Single().Id; newUser.FirstName = user.ScholarshipHolder.Single().FirstName; newUser.LastName = user.ScholarshipHolder.Single().LastName; newUser.BirthDate = user.ScholarshipHolder.Single().BirthDate; newUser.PhoneNum = user.ScholarshipHolder.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Donator) { if (user.Donator.Any()) { newUser.Id = user.Donator.Single().Id; newUser.FirstName = user.Donator.Single().FirstName; newUser.LastName = user.Donator.Single().LastName; newUser.BirthDate = user.Donator.Single().BirthDate; newUser.PhoneNum = user.Donator.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Schoolmaster) { if (user.Schoolmaster.Any()) { newUser.Id = user.Schoolmaster.Single().Id; newUser.FirstName = user.Schoolmaster.Single().FirstName; newUser.LastName = user.Schoolmaster.Single().LastName; newUser.BirthDate = user.Schoolmaster.Single().BirthDate; newUser.PhoneNum = user.Schoolmaster.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.HostSchoolTeacher) { if (user.HostSchoolTeacher.Any()) { newUser.Id = user.HostSchoolTeacher.Single().Id; newUser.FirstName = user.HostSchoolTeacher.Single().FirstName; newUser.LastName = user.HostSchoolTeacher.Single().LastName; newUser.BirthDate = user.HostSchoolTeacher.Single().BirthDate; newUser.PhoneNum = user.HostSchoolTeacher.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Student) { if (user.Student.Any()) { newUser.Id = user.Student.Single().Id; newUser.FirstName = user.Student.Single().FirstName; newUser.LastName = user.Student.Single().LastName; newUser.BirthDate = user.Student.Single().BirthDate; newUser.PhoneNum = user.Student.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.Volunteer) { if (user.Volunteer.Any()) { newUser.Id = user.Volunteer.Single().Id; newUser.FirstName = user.Volunteer.Single().FirstName; newUser.LastName = user.Volunteer.Single().LastName; newUser.BirthDate = user.Volunteer.Single().BirthDate; newUser.PhoneNum = user.Volunteer.Single().PhoneNumber; } } if (user.UserTypeId == (int)EnumUserType.YonDer) { if (user.YonDer.Any()) { newUser.Id = user.YonDer.Single().Id; newUser.FirstName = user.YonDer.Single().FirstName; newUser.LastName = user.YonDer.Single().LastName; newUser.BirthDate = user.YonDer.Single().BirthDate; newUser.PhoneNum = user.YonDer.Single().PhoneNumber; } } result.Add(newUser); } serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <List <UserDTO> > { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }