public async Task <EntityActionOutcome> UpdateEntityAsync(PeripheralInputData viewData, Guid id) { var assignedChildrenAmount = await _repository.GetChildrenAssignedToParentAsync(viewData.GatewayId); var validator = new PeripheralDataInputValidator(); var result = validator.Validate(viewData); if (result.IsValid == false) { return(EntityActionOutcome.UpdateFailed); } if (viewData.GatewayId != null && assignedChildrenAmount >= _assignedDevicesAmount) { return(EntityActionOutcome.PeripheralsLimitReached); } var updateSuccessful = await _repository.UpdateAsync( await PopulateEntityDataWithViewData(viewData, id)); if (updateSuccessful == null) { return(EntityActionOutcome.EntityNotFound); } return(EntityActionOutcome.Success); }
public async Task <EntityActionOutcome> CreateEntityAsync(PeripheralInputData viewData) { var newEntity = _factory.Create(viewData); var assignedChildrenAmount = await _repository.GetChildrenAssignedToParentAsync(viewData.GatewayId); var validator = new PeripheralDataInputValidator(); var result = validator.Validate(viewData); if (result.IsValid == false) { return(EntityActionOutcome.MissingFullEntityData); } if (viewData.GatewayId != null && assignedChildrenAmount >= _assignedDevicesAmount) { return(EntityActionOutcome.PeripheralsLimitReached); } var upsertSuccessful = await _repository.AddAsync(newEntity); if (upsertSuccessful == null) { return(EntityActionOutcome.CreateFailed); } return(EntityActionOutcome.Success); }
private async Task <Peripheral> PopulateEntityDataWithViewData(PeripheralInputData viewData, Guid entityId) { var getCurrent = await _repository.GetByIdAsync <Peripheral>(entityId); getCurrent.UID = viewData?.UID ?? getCurrent.UID; getCurrent.GatewayId = viewData?.GatewayId ?? getCurrent.GatewayId; getCurrent.Vendor = viewData.Vendor ?? getCurrent.Vendor; getCurrent.Status = viewData?.Status ?? getCurrent.Status; return(getCurrent); }
public Peripheral Create(PeripheralInputData viewData) { return(new Peripheral { UID = viewData.UID, Vendor = viewData.Vendor, GatewayId = viewData.GatewayId, Status = viewData.Status, DateCreated = DateTime.Now.ToString() }); }
public async Task <HttpStatusCode> Update(PeripheralInputData inputData, Guid id) { var updateEntityOutcome = await _service.UpdateEntityAsync(inputData, id); return(_resultFactory.Create(updateEntityOutcome)); }
public async Task <HttpStatusCode> Create(PeripheralInputData inputData) { var createEntityOutcome = await _service.CreateEntityAsync(inputData); return(_resultFactory.Create(createEntityOutcome)); }