public async Task <ResponseResult <ProductEntityDomain> > InvokeAsync(ProductEntityDomain productEntityDomain) { if (!productEntityDomain.Validate()) { return(ResponseResult <ProductEntityDomain> .Failed(400, "Existem campos inválidos", productEntityDomain.Notifications)); } productEntityDomain.Id = Guid.NewGuid().ToString(); productEntityDomain.Active = 1; productEntityDomain.CreatedAt = DateTime.Now; ProductEntityDomain resultData = await _productRepository.CreateProductAsync(productEntityDomain); return(ResponseResult <ProductEntityDomain> .Succeeded(resultData, 201)); }
public async Task <IActionResult> AddContactToCompanyAsync(string id, AddContactCompanyInputModel model) { if (string.IsNullOrEmpty(id)) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Company Id can't be empty."))); } var company = await _companyRepository.GetCompanyByIdAsync(id); if (company is null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Company isn't found."))); } if (string.IsNullOrEmpty(model.ContactId)) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Contact Id can't be empty."))); } var contact = await _contactRepository.GetContactByIdAsync(model.ContactId); if (contact is null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Contact isn't found."))); } var isExist = company.ContactIds != null?company.ContactIds.FirstOrDefault(x => x == model.ContactId) : null; if (isExist != null) { return(BadRequest(ResponseResult.Failed(ErrorCode.Error, "Contact is already exist."))); } company.AddContact(model.ContactId); contact.AddCompany(company.Id); await _companyRepository.UpdateCompanyAsync(company); await _contactRepository.UpdateContactAsync(contact); return(Ok(ResponseResult.Succeeded())); }
public async Task <IActionResult> DeleteContactByIdAsync(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Contact Id can't be empty."))); } var contact = await _contactRepository.GetContactByIdAsync(id); if (contact is null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "no hit information"))); } contact.Delete(); await _contactRepository.DeleteContactAsync(contact); return(Ok(ResponseResult.Succeeded())); }
public async Task <IActionResult> DeleteCompanyByIdAsync(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Company Id can't be empty."))); } var company = await _companyRepository.GetCompanyByIdAsync(id); if (company is null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Company isn't found."))); } company.Delete(); await _companyRepository.DeleteCompanyAsync(company); return(Ok(ResponseResult.Succeeded())); }
public async Task <IActionResult> UploadDataByDatasetIdAsync(long id, IFormFile file) { if (file == null) { return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "File can't be empty."))); } var dataset = await _datasetRepository.GetDatasetByIdAsync(id); if (dataset == null) { return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Dataset isn't found."))); } if (dataset.IsImported) { return(BadRequest(ResponseResult.Failed(ErrorCode.Error, "Dataset can't be imported more than once."))); } var friendships = new List <Friendship>(); using (StreamReader streamReader = new StreamReader(file.OpenReadStream())) { string line; while ((line = streamReader.ReadLine()) != null) { var fields = line.Split(' '); friendships.Add(Friendship.New(long.Parse(fields[0]), long.Parse(fields[1]), dataset)); } } await _friendShipRepository.AddDataAsync(friendships); dataset.Update(); await _datasetRepository.UpdateDatasetAsync(dataset); return(Ok(ResponseResult.Succeeded())); }