public async Task <ChatLogHistoryModel> GetThreadByParticipantsAsync(string studentUniqueId, string senderUniqueId, int senderTypeid, string recipientUniqueId, int recipientTypeId, int rowsToSkip, int?unreadMessageCount, int rowsToRetrieve = 15)
        {
            // Ensures the method returns all unread messages
            var messagesToTake = 0;
            var unreadMessages = unreadMessageCount.HasValue ? unreadMessageCount.Value : await _edFiDb.ChatLogs.CountAsync(x => x.SenderUniqueId == recipientUniqueId && x.SenderTypeId == recipientTypeId && x.RecipientTypeId == senderTypeid && x.RecipientUniqueId == senderUniqueId);

            messagesToTake = unreadMessages > rowsToRetrieve ? unreadMessages : rowsToRetrieve;

            var data = await(from c in _edFiDb.ChatLogs
                             where c.StudentUniqueId == studentUniqueId &&
                             (c.SenderUniqueId == senderUniqueId &&
                              c.RecipientUniqueId == recipientUniqueId &&
                              c.RecipientTypeId == recipientTypeId &&
                              c.SenderTypeId == senderTypeid ||
                              (c.SenderUniqueId == recipientUniqueId &&
                               c.RecipientUniqueId == senderUniqueId &&
                               c.RecipientTypeId == senderTypeid &&
                               c.SenderTypeId == recipientTypeId))
                             orderby c.DateSent descending
                             select c).ToListAsync();

            var dataNeeded = data.Skip(rowsToSkip).Take(messagesToTake).Reverse().ToList();

            dataNeeded.ForEach(x => {
                if (x.RecipientUniqueId.Equals(senderUniqueId))
                {
                    x.RecipientHasRead = true;
                }
            });

            await _edFiDb.SaveChangesAsync();

            var returnList = dataNeeded.Select(x => new ChatLogItemModel
            {
                StudentUniqueId   = x.StudentUniqueId,
                SenderUniqueId    = x.SenderUniqueId,
                RecipientUniqueId = x.RecipientUniqueId,
                OriginalMessage   = x.OriginalMessage,
                EnglishMessage    = x.EnglishMessage,
                DateSent          = x.DateSent,
                RecipientTypeId   = x.RecipientTypeId,
                SenderTypeId      = x.SenderTypeId,
                RecipientHasRead  = x.RecipientHasRead
            }).ToList();

            var result = new ChatLogHistoryModel
            {
                Messages            = returnList,
                EndOfMessageHistory = rowsToSkip + rowsToRetrieve >= data.Count()
            };

            return(result);
        }
        public async Task <FeedbackLogModel> SaveFeedback(string uniqueId, int personTypeId, string name, string email, FeedbackRequestModel model)
        {
            var newFeedback = new FeedbackLog
            {
                PersonUniqueId = uniqueId,
                Name           = name,
                Email          = email,
                PersonTypeId   = ChatLogPersonTypeEnum.Parent.Value,
                Subject        = model.Subject,
                Issue          = model.Issue,
                Description    = model.Description,
                CurrentUrl     = model.CurrentUrl
            };

            _edFiDb.FeedbackLogs.Add(newFeedback);


            await _edFiDb.SaveChangesAsync();

            return(new FeedbackLogModel {
                PersonUniqueId = newFeedback.PersonUniqueId,
                Name = newFeedback.Name,
                Email = newFeedback.Email,
                PersonTypeId = newFeedback.PersonTypeId,
                Subject = newFeedback.Subject,
                Issue = newFeedback.Issue,
                Description = newFeedback.Description,
                CurrentUrl = newFeedback.CurrentUrl,
                CreatedDate = newFeedback.CreateDate
            });
        }
 public async Task AddLogEntryAsync(string message, string logType)
 {
     _edFiDb.Logs.Add(new Log()
     {
         LogMessage = message, LogType = logType
     });
     await _edFiDb.SaveChangesAsync();
 }
        public async Task <AdminStudentDetailFeatureModel> SaveStudentDetailFeatures(AdminStudentDetailFeatureModel model)
        {
            AdminStudentDetailFeatureModel result = new AdminStudentDetailFeatureModel();

            if (model.AdminStudentDetailFeaturesId == 0)
            {
                var newRecord = _edFiDb.AdminStudentDetailFeatures.Add(new AdminStudentDetailFeature
                {
                    AllAboutMe                  = model.AllAboutMe,
                    Arc                         = model.Arc,
                    Assessment                  = model.Assessment,
                    AttendanceIndicator         = model.AttendanceIndicator,
                    AttendanceLog               = model.AttendanceLog,
                    CourseAverageIndicator      = model.CourseAverageIndicator,
                    MissingAssignments          = model.MissingAssignments,
                    MissingAssignmentsIndicator = model.MissingAssignmentsIndicator,
                    StaarAssessment             = model.StaarAssessment,
                    BehaviorIndicator           = model.BehaviorIndicator,
                    BehaviorLog                 = model.BehaviorLog,
                    Calendar                    = model.Calendar,
                    CollegeInitiativeCorner     = model.CollegeInitiativeCorner,
                    CourseGrades                = model.CourseGrades,
                    Goals                       = model.Goals,
                    Profile                     = model.Profile,
                    SuccessTeam                 = model.SuccessTeam,
                    DateCreated                 = DateTime.Now,
                    DateUpdated                 = DateTime.Now,
                });

                await _edFiDb.SaveChangesAsync();

                model.AdminStudentDetailFeaturesId = newRecord.AdminStudentDetailFeaturesId;
                model.DateCreated = newRecord.DateCreated;
                model.DateUpdated = newRecord.DateUpdated;
            }
            else
            {
                var recordToUpdate = await _edFiDb.AdminStudentDetailFeatures.FirstOrDefaultAsync(rec => rec.AdminStudentDetailFeaturesId == model.AdminStudentDetailFeaturesId);

                recordToUpdate.AdminStudentDetailFeaturesId = model.AdminStudentDetailFeaturesId;
                recordToUpdate.AllAboutMe                  = model.AllAboutMe;
                recordToUpdate.Arc                         = model.Arc;
                recordToUpdate.Assessment                  = model.Assessment;
                recordToUpdate.AttendanceIndicator         = model.AttendanceIndicator;
                recordToUpdate.AttendanceLog               = model.AttendanceLog;
                recordToUpdate.BehaviorIndicator           = model.BehaviorIndicator;
                recordToUpdate.BehaviorLog                 = model.BehaviorLog;
                recordToUpdate.Calendar                    = model.Calendar;
                recordToUpdate.CollegeInitiativeCorner     = model.CollegeInitiativeCorner;
                recordToUpdate.CourseAverageIndicator      = model.CourseAverageIndicator;
                recordToUpdate.CourseGrades                = model.CourseGrades;
                recordToUpdate.DateCreated                 = model.DateCreated;
                recordToUpdate.DateUpdated                 = model.DateUpdated;
                recordToUpdate.Goals                       = model.Goals;
                recordToUpdate.MissingAssignments          = model.MissingAssignments;
                recordToUpdate.MissingAssignmentsIndicator = model.MissingAssignmentsIndicator;
                recordToUpdate.Profile                     = model.Profile;
                recordToUpdate.StaarAssessment             = model.StaarAssessment;
                recordToUpdate.SuccessTeam                 = model.SuccessTeam;
                recordToUpdate.DateUpdated                 = DateTime.Now;
                await _edFiDb.SaveChangesAsync();
            }

            result = model;
            return(result);
        }