Example #1
0
        public override async Task <MobileCalibrationRecord> InsertAsync(MobileCalibrationRecord mobileCalibrationRecord)
        {
            Flowswitch flowswitch = await VerifyMobileFlowswitch(mobileCalibrationRecord.MobileFlowswitchId, mobileCalibrationRecord.MobileFlowswitchName);

            mobileCalibrationRecord.FlowswitchID = flowswitch.ID;
            return(await base.InsertAsync(mobileCalibrationRecord));
        }
Example #2
0
        public override async Task <MobileCalibrationRecord> UpdateAsync(string mobileCalibrationRecordId, Delta <MobileCalibrationRecord> patch)
        {
            Flowswitch flowswitch = await VerifyMobileFlowswitch(patch.GetEntity().MobileFlowswitchId, patch.GetEntity().MobileFlowswitchName);

            int ID = GetKey <int>(mobileCalibrationRecordId);

            CalibrationRecord existingCalibrationRecord = await this.Context.Set <CalibrationRecord>().FindAsync(ID);

            if (existingCalibrationRecord == null)
            {
                throw new HttpResponseException(this.Request.CreateNotFoundResponse());
            }

            MobileCalibrationRecord existingCalibrationRecordDTO = Mapper.Map <CalibrationRecord, MobileCalibrationRecord>(existingCalibrationRecord);

            patch.Patch(existingCalibrationRecordDTO);
            Mapper.Map <MobileCalibrationRecord, CalibrationRecord>(existingCalibrationRecordDTO, existingCalibrationRecord);

            // This is required to map the right Id for the flowswitch
            existingCalibrationRecord.FlowswitchID = flowswitch.ID;

            await this.SubmitChangesAsync();

            MobileCalibrationRecord updatedCalibrationRecordDTO = Mapper.Map <CalibrationRecord, MobileCalibrationRecord>(existingCalibrationRecord);

            return(updatedCalibrationRecordDTO);
        }
Example #3
0
        private async Task <Flowswitch> VerifyMobileFlowswitch(string mobileFlowswitchId, string mobileFlowswitchName)
        {
            int        ID         = MobileFlowswitchDomainManager.GetKey(mobileFlowswitchId, this.context.Flowswitches, this.Request);
            Flowswitch flowswitch = await this.context.Flowswitches.FindAsync(ID);

            if (flowswitch == null)
            {
                throw new HttpResponseException(Request.CreateBadRequestResponse("Flowswitch with name '{0}' was not found", mobileFlowswitchName));
            }
            return(flowswitch);
        }