示例#1
0
 public Gateway Create(GatewayInputData viewData)
 {
     return(new Gateway
     {
         SerialNumber = viewData.SerialNumber,
         Name = viewData.Name,
         IPv4 = viewData.IPv4
     });
 }
        private async Task <Gateway> PopulateEntityDataWithViewData(GatewayInputData viewData, Guid entityId)
        {
            var getCurrent = await _repository.GetByIdAsync <Gateway>(entityId);

            getCurrent.IPv4         = viewData?.IPv4 ?? getCurrent.IPv4;
            getCurrent.Name         = viewData.Name ?? getCurrent.Name;
            getCurrent.SerialNumber = viewData.SerialNumber ?? getCurrent.SerialNumber;

            return(getCurrent);
        }
        public async Task <EntityActionOutcome> UpdateEntityAsync(GatewayInputData viewData, Guid id)
        {
            var validator = new GatewayDataInputValidator();
            var result    = validator.Validate(viewData);

            if (result.IsValid == false)
            {
                return(EntityActionOutcome.UpdateFailed);
            }

            var updateSuccessful = await _repository.UpdateAsync(
                await PopulateEntityDataWithViewData(viewData, id));

            if (updateSuccessful == null)
            {
                return(EntityActionOutcome.EntityNotFound);
            }

            return(EntityActionOutcome.Success);
        }
        public async Task <EntityActionOutcome> CreateEntityAsync(GatewayInputData viewData)
        {
            var newEntity = _factory.Create(viewData);
            var validator = new GatewayDataInputValidator();
            var result    = validator.Validate(viewData);

            if (result.IsValid == false)
            {
                return(EntityActionOutcome.MissingFullEntityData);
            }

            var upsertSuccessful = await _repository.AddAsync(newEntity);

            if (upsertSuccessful == null)
            {
                return(EntityActionOutcome.CreateFailed);
            }

            return(EntityActionOutcome.Success);
        }
示例#5
0
        public async Task <HttpStatusCode> Update(GatewayInputData inputData, Guid id)
        {
            var updateEntityOutcome = await _service.UpdateEntityAsync(inputData, id);

            return(_resultFactory.Create(updateEntityOutcome));
        }
示例#6
0
        public async Task <HttpStatusCode> Create(GatewayInputData inputData)
        {
            var createEntityOutcome = await _service.CreateEntityAsync(inputData);

            return(_resultFactory.Create(createEntityOutcome));
        }