示例#1
0
        public NoteApprovedRecord AddOrUpdateToNotCancel(int noteId, int userId)
        {
            NoteApprovedRecordEntity entity = this.dbContext.NoteApprovedRecords
                                              .FirstOrDefault(na => na.NoteId == noteId && na.UserId == userId);

            if (entity == null)
            {
                entity = new NoteApprovedRecordEntity()
                {
                    ApprovedTime = DateTime.Now,
                    CanceledTime = DateTime.Now,
                    IsCanceled   = false,
                    NoteId       = noteId,
                    UserId       = userId,
                };

                this.dbContext.NoteApprovedRecords.Add(entity);
                this.dbContext.SaveChanges();
                return(entity.ToModel());
            }
            else
            {
                entity.IsCanceled = false;
                this.dbContext.SaveChanges();
                return(entity.ToModel());
            }
        }
示例#2
0
        public NoteApprovedRecord GetNoteApprovedRecordByNoteIdAndUserId(int noteId, int userId)
        {
            NoteApprovedRecordEntity entity = this.dbContext.NoteApprovedRecords
                                              .FirstOrDefault(na => na.NoteId == noteId && na.UserId == userId);

            return(entity == null ? null : entity.ToModel());
        }
示例#3
0
        public List <NoteApprovedRecord> GetNoteApprovedRecordsByUserId(int userId)
        {
            try
            {
                if (userId <= 0)
                {
                    return(null);
                }

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

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

                    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)
                        {
                            NoteApprovedRecordEntity entity = new NoteApprovedRecordEntity()
                            {
                                Id           = (int)dataRow[dataColumns[0]],
                                UserId       = (int)dataRow[dataColumns[1]],
                                NoteId       = (int)dataRow[dataColumns[2]],
                                ApprovedTime = (DateTime)dataRow[dataColumns[3]],
                                IsCanceled   = (bool)dataRow[dataColumns[4]],
                                CanceledTime = (DateTime)dataRow[dataColumns[5]]
                            };

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

                    return(noteApprovedRecords);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#4
0
        public NoteApprovedRecord GetCanceled(int noteId, int userId)
        {
            NoteApprovedRecordEntity entity = this.dbContext.NoteApprovedRecords
                                              .FirstOrDefault(na => na.NoteId == noteId && na.UserId == userId);

            if (entity == null)
            {
                return(null);
            }
            else
            {
                entity.IsCanceled = true;
                this.dbContext.SaveChanges();
                return(entity.ToModel());
            }
        }