public async Task <BaseResponse> StartWatering(PlantRequest plantRequest, CancellationToken cancellationToken) { BaseResponse baseResponse = new BaseResponse(); Plant plant = await _plantsRepository.GetById(plantRequest.Id); if (plant != null) { TimeSpan timeSpan = DateTime.Now - plant.LastWateringDate; if (timeSpan.TotalHours < 6) { return(baseResponse.ToToMuchWateringError <BaseResponse>()); } else { for (int i = 0; i < 10; i++) { cancellationToken.ThrowIfCancellationRequested(); Thread.Sleep(1000); } plant.LastWateringDate = DateTime.Now; await _plantsRepository.Update(plant); return(baseResponse.ToSuccess <BaseResponse>()); } } else { return(baseResponse.ToNotFoundError <BaseResponse>()); } }
//public SACOMaintenanceContext SacoMaintenanceContext { get; } public void AddEditPlantRequestInfo(int maintReqId, PlantRequest plantRequest) { _areaDBContext.PlantRequests.Add ( new PlantRequest { IsolationNitricAcid = plantRequest.IsolationNitricAcid, IsolatedPhosphoricAcid = plantRequest.IsolatedPhosphoricAcid, IsolatedSodiumHydroxide = plantRequest.IsolatedSodiumHydroxide, IsolatedSulphuricAcid = plantRequest.IsolatedSulphuricAcid, IsolatedOther = plantRequest.IsolatedOther, DrainingLinesNitricAcid = plantRequest.DrainingLinesNitricAcid, DrainingLinesSodiumHydroxide = plantRequest.DrainingLinesSodiumHydroxide, DrainingLinesSulphuricAcid = plantRequest.DrainingLinesSulphuricAcid, DrainingLinesOther = plantRequest.DrainingLinesOther, IsolationsCompressedAir = plantRequest.IsolationsCompressedAir, IsolationsElectrical = plantRequest.IsolationsElectrical, IsolationsGas = plantRequest.IsolationsGas, IsolationsMechanical = plantRequest.IsolationsMechanical, IsolationsSteam = plantRequest.IsolationsSteam, IsolationsWater = plantRequest.IsolationsWater, IsolationsOther = plantRequest.IsolationsOther, OtherPrecautions = plantRequest.OtherPrecautions, AuthorisationToWorkUserId = plantRequest.AuthorisationToWorkUserId, AuthorisationDatTime = plantRequest.AuthorisationDatTime, ReceiptPersonDoingWorkUserId = plantRequest.ReceiptPersonDoingWorkUserId, ReceiptCompanyId = plantRequest.ReceiptCompanyId, ClearancePosition = plantRequest.ClearancePosition, ClearanceDateTime = plantRequest.ClearanceDateTime, MaintRequestId = plantRequest.MaintRequestId } ); _areaDBContext.SaveChanges(); }
public async Task <BaseResponse> Create(PlantRequest plantRequest) { BaseResponse baseResponse = new BaseResponse(); try { Plant plant = new Plant(); plantRequest.CopyPropertiesTo(plant); await _plantsRepository.Add(plant); return(baseResponse.ToSuccess <BaseResponse>()); } catch (Exception ex) { return(baseResponse.ToApiError <BaseResponse>()); } }
public async Task <BaseResponse> Update(PlantRequest plantRequest) { BaseResponse baseResponse = new BaseResponse(); try { Plant plant = new Plant(); plant.UpdatedBy = plantRequest.UserName; plant.UpdatedDate = DateTime.Now; plantRequest.CopyPropertiesTo(plant); await _plantsRepository.Update(plant); return(baseResponse.ToSuccess <BaseResponse>()); } catch (Exception ex) { return(baseResponse.ToApiError <BaseResponse>()); } }
public async Task <BaseResponse> StartWatering([FromBody] PlantRequest plantRequest, CancellationToken cancelToken) { return(await _plantsService.StartWatering(plantRequest, cancelToken)); }
public async Task <BaseResponse> Update([FromBody] PlantRequest plantRequest) { BaseResponse baseResponse = await _plantsService.Create(plantRequest); return(baseResponse); }