public Company Create(CompanyInputData viewData)
 {
     return(new Company
     {
         Name = viewData.Name,
         CreatedAt = DateTime.Now.ToString()
     });
 }
        private async Task <Company> PopulateEntityDataWithViewData(CompanyInputData viewData, Guid entityId)
        {
            var getCurrent = await _repository.GetByIdAsync <Company>(entityId);

            getCurrent.Name = viewData.Name ?? getCurrent.Name;

            return(getCurrent);
        }
        public async Task <EntityActionOutcome> UpdateEntityAsync(CompanyInputData viewData)
        {
            var validator = new CompanyDataInputValidator();
            var result    = validator.Validate(viewData);

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

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

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

            return(EntityActionOutcome.Success);
        }
        public async Task <EntityActionOutcome> CreateEntityAsync(CompanyInputData viewData)
        {
            var newEntity = _factory.Create(viewData);
            var validator = new CompanyDataInputValidator();
            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);
        }
Esempio n. 5
0
        public async Task <HttpStatusCode> Update(CompanyInputData inputData)
        {
            var updateEntityOutcome = await _service.UpdateEntityAsync(inputData);

            return(_resultFactory.Create(updateEntityOutcome));
        }