Пример #1
0
        public NoteBrowsedRecord AddNoteBrowsedRecord(int noteId, int userId)
        {
            NoteBrowsedRecordEntity entity = new NoteBrowsedRecordEntity()
            {
                BrowsedTime = DateTime.Now,
                NoteId      = noteId,
                UserId      = userId,
            };

            this.dbContext.NoteBrowsedRecords.Add(entity);
            this.dbContext.SaveChanges();
            return(entity.ToModel());
        }
Пример #2
0
        public List <NoteBrowsedRecord> GetNoteBrowsedRecordsByUserId(int userId)
        {
            try
            {
                if (userId <= 0)
                {
                    return(null);
                }

                DbParameter[] parameters = new DbParameter[]
                {
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfNoteBrowsedRecord.Sp_Select_NoteBrowsedRecordsByUserId_UserId,
                        Value         = userId
                    }
                };

                using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfNoteApprovedRecord.Sp_Select_NoteApprovedRecordsByUserId, parameters))
                {
                    List <NoteBrowsedRecord> noteBrowsedRecords = new List <NoteBrowsedRecord>();

                    if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0)
                    {
                        DataRowCollection    dataRows    = dataSet.Tables[0].Rows;
                        DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                        foreach (DataRow dataRow in dataRows)
                        {
                            NoteBrowsedRecordEntity entity = new NoteBrowsedRecordEntity()
                            {
                                Id          = (int)dataRow[dataColumns[0]],
                                UserId      = (int)dataRow[dataColumns[1]],
                                NoteId      = (int)dataRow[dataColumns[2]],
                                BrowsedTime = (DateTime)dataRow[dataColumns[3]]
                            };

                            noteBrowsedRecords.Add(entity.ToModel());
                        }
                    }

                    return(noteBrowsedRecords);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public NoteBrowsedRecord NoteGetBrowsed(int noteId, int userId)
        {
            NoteEntity entity = this.dbContext.Notes.FirstOrDefault(n => n.Id == noteId && n.AuthorId == userId);

            if (entity != null)
            {
                entity.LastBrowsedTime = DateTime.Now;
            }

            NoteBrowsedRecordEntity browsedRecordEntity = new NoteBrowsedRecordEntity()
            {
                BrowsedTime = DateTime.Now,
                NoteId      = noteId,
                UserId      = userId
            };

            this.dbContext.NoteBrowsedRecords.Add(browsedRecordEntity);
            this.dbContext.SaveChanges();
            return(browsedRecordEntity.ToModel());
        }