示例#1
0
 public static RestServiceResponse Add(InspectionRecord inspectionRecord)
 {
     return(new ServiceClientBase("operate-inspection-record").Call <RestServiceResponse <InspectionRecord> >(new RestServiceRequest <InspectionRecord>()
     {
         Body = inspectionRecord,
         ActionName = "Add"
     }));
 }
示例#2
0
        public static InspectionRecordSource BuildInspectionRecordSource(InspectionRecord inspectionRecord)
        {
            if (inspectionRecord == null)
            {
                return(null);
            }

            var inspectionRecordSource = new InspectionRecordSource();

            inspectionRecordSource.Content           = inspectionRecord.Content;
            inspectionRecordSource.DeviceInfo        = DeviceInfoTransfer.BuildDeviceInfoSource(inspectionRecord.DeviceInfo);
            inspectionRecordSource.Id                = inspectionRecord.Id;
            inspectionRecordSource.InspectionPlan    = InspectionPlanTransfer.BuildInspectionPlanSource(inspectionRecord.InspectionPlan);
            inspectionRecordSource.MaintainBeginTime = Utility.ConvertDateTime(inspectionRecord.MaintainBeginTime);
            inspectionRecordSource.MaintainEndTime   = Utility.ConvertDateTime(inspectionRecord.MaintainEndTime);
            inspectionRecordSource.Persons           = inspectionRecord.Persons;
            inspectionRecordSource.Remark            = inspectionRecord.Remark;
            inspectionRecordSource.ScheduleTime      = Utility.ConvertDateTime(inspectionRecord.ScheduleTime);
            inspectionRecordSource.Status            = typeof(InspectionRecordStatus).GetValueByEnum(inspectionRecord.Status);

            return(inspectionRecordSource);
        }
示例#3
0
        public static InspectionRecord BuildInspectionRecord(InspectionRecordSource inspectionRecordSource)
        {
            if (inspectionRecordSource == null)
            {
                return(null);
            }

            var inspectionRecord = new InspectionRecord();

            inspectionRecord.Content           = inspectionRecordSource.Content;
            inspectionRecord.CreationDate      = Utility.ConvertDateTime(inspectionRecordSource.CreationDate);
            inspectionRecord.DeviceInfo        = DeviceInfoTransfer.BuildDeviceInfo(inspectionRecordSource.DeviceInfo);
            inspectionRecord.Id                = inspectionRecordSource.Id;
            inspectionRecord.InspectionPlan    = InspectionPlanTransfer.BuildInspectionPlan(inspectionRecordSource.InspectionPlan);
            inspectionRecord.MaintainBeginTime = Utility.ConvertDateTime(inspectionRecordSource.MaintainBeginTime);
            inspectionRecord.MaintainEndTime   = Utility.ConvertDateTime(inspectionRecordSource.MaintainEndTime);
            inspectionRecord.ModifiedDate      = Utility.ConvertDateTime(inspectionRecordSource.ModifiedDate);
            inspectionRecord.Persons           = inspectionRecordSource.Persons;
            inspectionRecord.Remark            = inspectionRecordSource.Remark;
            inspectionRecord.ScheduleTime      = Utility.ConvertDateTime(inspectionRecordSource.ScheduleTime);
            inspectionRecord.Status            = (InspectionRecordStatus)typeof(InspectionRecordStatus).GetEnumByValue(inspectionRecordSource.Status);

            return(inspectionRecord);
        }
示例#4
0
        private static async Task ImportInspectionRecordAsync(NesteoDbContext dbContext, InspectionRecord inspectionRecord)
        {
            // Create collection for comments
            var comments = new List <string>();

            if (!string.IsNullOrWhiteSpace(inspectionRecord.Comments))
            {
                comments.AddRange(inspectionRecord.Comments.Split(',').Select(c => c.Trim()).Where(c => !string.IsNullOrEmpty(c)));
            }

            // Get nesting box entity
            NestingBoxEntity nestingBoxEntity = await dbContext.NestingBoxes.FindAsync(inspectionRecord.NestingBoxId).ConfigureAwait(false);

            if (nestingBoxEntity == null)
            {
                throw new InvalidCsvRecordException($"Nesting box {inspectionRecord.NestingBoxId} doesn't exist.");
            }

            // Ensure the species entity exists
            SpeciesEntity speciesEntity = null;

            if (!string.IsNullOrWhiteSpace(inspectionRecord.SpeciesName) &&
                !new[] { "unbestimmt", "unbekannt" }.Contains(inspectionRecord.SpeciesName.ToLower()))
            {
                speciesEntity = await GetOrCreateEntityAsync(dbContext, species => species.Name == inspectionRecord.SpeciesName,
                                                             () => new SpeciesEntity { Name = inspectionRecord.SpeciesName }).ConfigureAwait(false);
            }

            // Analyze date info
            DateTime inspectionDate = string.IsNullOrWhiteSpace(inspectionRecord.Date)
                ? throw new InvalidCsvRecordException("Inspection date not set.")
                : ParseDate(inspectionRecord.Date);

            // Map nesting box condition
            (Condition condition, bool justRepaired) = GetCondition(inspectionRecord.Condition);
            if (condition != Condition.Good)
            {
                comments.Add($"Kasten-Zustand: {inspectionRecord.Condition}");
            }

            // Analyze ringing activity
            (ParentBirdDiscovery femaleParentBirdDiscovery, ParentBirdDiscovery maleParentBirdDiscovery, int ringedChickCount) =
                AnalyzeRingingActivity(inspectionRecord.RingedCount);

            // Create inspection
            dbContext.Inspections.Add(new InspectionEntity {
                NestingBox                = nestingBoxEntity,
                InspectionDate            = inspectionDate,
                InspectedByUser           = null,
                HasBeenCleaned            = GetYesNo(inspectionRecord.HasBeenCleaned),
                Condition                 = condition,
                JustRepaired              = justRepaired,
                Occupied                  = GetYesNoWithUnknown(inspectionRecord.Occupied),
                ContainsEggs              = !string.IsNullOrWhiteSpace(inspectionRecord.EggCount),
                EggCount                  = ParseNumberWithUnknown(inspectionRecord.EggCount),
                ChickCount                = ParseNumberWithUnknown(inspectionRecord.ChickCount),
                RingedChickCount          = ringedChickCount,
                AgeInDays                 = ParseNumberWithUnknown(inspectionRecord.ChickAges),
                FemaleParentBirdDiscovery = femaleParentBirdDiscovery,
                MaleParentBirdDiscovery   = maleParentBirdDiscovery,
                Species       = speciesEntity,
                ImageFileName = null,
                Comment       = comments.Any() ? string.Join(", ", comments) : null,
                LastUpdated   = inspectionDate
            });
        }
示例#5
0
 public int EditRecord(InspectionRecord inspectionRecord)
 {
     throw new NotImplementedException();
 }