示例#1
0
 public static IEnumerable <DeviceSurvey> GetAll()
 {
     using (var context = new ClipperContext())
     {
         return(context.DeviceSurveys.OrderBy(x => x.ReportingPeriod).ThenBy(x => x.Operator).ThenBy(x => x.RecordStatus).ToList());
     }
 }
示例#2
0
 public static DeviceSurvey Get(int id)
 {
     using (var context = new ClipperContext())
     {
         return(context.DeviceSurveys.Find(id));
     }
 }
 public static IEnumerable <ReportingPeriod> GetReportingPeriods()
 {
     using (var context = new ClipperContext())
     {
         return(context.ReportingPeriods.ToList());
     }
 }
 public static IEnumerable <Operator> GetOperators()
 {
     using (var context = new ClipperContext())
     {
         return(context.Operators.ToList());
     }
 }
 public static IEnumerable <AuditRecord> GetAll()
 {
     using (var context = new ClipperContext())
     {
         return(context.AuditRecords.ToList());
     }
 }
 public static void Create(AuditRecord auditRecord)
 {
     using (var context = new ClipperContext())
     {
         context.AuditRecords.Add(auditRecord);
         context.SaveChanges();
     }
 }
示例#7
0
        public static void Create(DeviceSurvey deviceSurvey)
        {
            var now = DateTime.UtcNow;

            using (var context = new ClipperContext())
            {
                context.DeviceSurveys.Add(deviceSurvey);
                context.Operator = deviceSurvey.Operator;
                context.UserName = deviceSurvey.UserName;
                context.SaveChanges(); // so we get the primary key of the created record

                // IF CREATING ONE AUDITRECORD FOR A NEW RECORD
                var auditRecord = new AuditRecord()
                {
                    EntityName      = "DeviceSurvey",
                    PrimaryKeyValue = deviceSurvey.ID.ToString(),
                    Action          = "Created",
                    PropertyName    = string.Empty,
                    OldValue        = null,
                    NewValue        = null,
                    DateChanged     = now,
                    UserName        = deviceSurvey.UserName,
                    Operator        = deviceSurvey.Operator
                };

                context.AuditRecords.Add(auditRecord);

                // IF CREATING AUDITRECORD FOR EACH FIELD OF A NEW RECORD
                //foreach (var prop in deviceSurvey.GetType().GetProperties())
                //{
                //    if (prop.Name == "DateCreated" || prop.Name == "LastUpdated")
                //    {
                //        continue;
                //    }

                //    var currentValue = prop.GetValue(deviceSurvey, null);
                //    var currentStringValue = currentValue == null ? "" : currentValue.ToString();

                //    var auditRecord = new AuditRecord()
                //    {
                //        EntityName = "DeviceSurvey",
                //        PrimaryKeyValue = deviceSurvey.ID.ToString(),
                //        Action = "Created",
                //        PropertyName = prop.Name,
                //        OldValue = null,
                //        NewValue = currentStringValue,
                //        DateChanged = now,
                //        UserName = deviceSurvey.UserName,
                //        Operator = deviceSurvey.Operator
                //    };

                //    context.AuditRecords.Add(auditRecord);
                //}

                context.SaveChanges();
            }
        }
示例#8
0
 public static void Update(DeviceSurvey deviceSurvey)
 {
     using (var context = new ClipperContext())
     {
         context.Entry(deviceSurvey).State = EntityState.Modified;
         context.Operator = deviceSurvey.Operator;
         context.UserName = deviceSurvey.UserName;
         context.SaveChanges();
     }
 }
示例#9
0
        public static void Delete(int id)
        {
            using (var context = new ClipperContext())
            {
                var deviceSurvey = context.DeviceSurveys.Find(id);

                if (deviceSurvey != null)
                {
                    context.DeviceSurveys.Remove(deviceSurvey);
                    context.Operator = deviceSurvey.Operator;
                    context.UserName = deviceSurvey.UserName;
                    context.SaveChanges();
                }
            }
        }