public async Task <VendorInsertResponseDTO> Insert(VendorInsertDTO dto) { var tagList = new List <Tag>(); if (dto.Tags != null && dto.Tags.Count > 0) { foreach (var Tag in dto.Tags) { var tag = new Tag() { Name = Tag.Name, Value = Tag.Value }; tagList.Add(tag); } } var vendor = new Vendor() { Name = dto.Name, Title = dto.Title, Date = dto.Date, Tags = tagList }; using TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var vendorResult = await _repository.Insert(vendor); VendorInsertResponseDTO vendorDTO = new VendorInsertResponseDTO() { Id = vendorResult.Id, Name = vendorResult.Name, Title = vendorResult.Title, Date = vendorResult.Date, Tags = vendorResult.Tags.Select(x => new TagDTO { Name = x.Name, Value = x.Value }).ToList() }; string json = JsonConvert.SerializeObject(vendorDTO); var history = new History() { VendorId = vendorDTO.Id, Operation = "Post", JsonResult = json, }; await _historyRepository.Insert(history); scope.Complete(); return(vendorDTO); }
public async Task <VendorInsertResponseDTO> InsertVendorAsync(VendorInsertDTO dto) { var tagList = new List <Tag>(); if (dto.Tags != null && dto.Tags.Count > 0) { foreach (var Tag in dto.Tags) { var tag = new Tag() { Name = Tag.Name, Value = Tag.Value }; tagList.Add(tag); } } string VendorId = Guid.NewGuid().ToString(); var vendor = new Vendor() { Id = VendorId, Name = dto.Name, Title = dto.Title, Date = dto.Date, Tags = tagList }; VendorInsertResponseDTO vendorDTO = new VendorInsertResponseDTO() { Id = vendor.Id, Name = vendor.Name, Title = vendor.Title, Date = vendor.Date, Tags = vendor.Tags.Select(x => new TagDTO { Name = x.Name, Value = x.Value }).ToList() }; string json = JsonConvert.SerializeObject(vendorDTO); var history = new History() { VendorId = vendorDTO.Id, Operation = "Post", JsonResult = json, }; await _historyRepository.InsertHistoryAndVendorAsync(vendor, history); return(vendorDTO); }
public IActionResult Insert(VendorInsertDTO dto) { var result = VendorService.Insert(dto); if (result) { return(Ok()); } else { throw new Exception(); } }
public bool Insert(VendorInsertDTO dto) { bool result = false; var tagList = new List <Tag>(); if (dto.Tags != null && dto.Tags.Count > 0) { foreach (var Tags in dto.Tags) { var tag = new Tag { Name = Tags.Name }; tagList.Add(tag); } } var vendor = new Vendor() { VendorName = dto.VendorName, Title = dto.Title, IsDeleted = dto.IsDeleted, Date = dto.Date, Tag = tagList }; int inserted = _VendorRepository.Insert(vendor); if (inserted > 0) { result = true; } return(result); }
public async Task <IActionResult> InsertVendorAsync([FromBody] VendorInsertDTO dto) { var insertVendorResponse = await _vendorService.InsertVendorAsync(dto); return(Created(new Uri($"http://localhost:49931/api/Vendors/{insertVendorResponse.Id}", UriKind.Relative), insertVendorResponse)); }
public async Task <IActionResult> Insert([FromBody] VendorInsertDTO dto) { var insertVendor = await _vendorService.Insert(dto); return(Created(new Uri($"/api/Vendors/{insertVendor.Id}", UriKind.Relative), insertVendor)); }
public async Task <VendorInsertResponseDTO> Insert(VendorInsertDTO dto) { string Id = Guid.NewGuid().ToString(); var tagList = new List <Tag>(); if (dto.Tags != null && dto.Tags.Count > 0) { foreach (var Tag in dto.Tags) { var tag = new Tag() { Name = Tag.Name, Value = Tag.Value }; tagList.Add(tag); } } VendorHistoryDTO vendorHistoryDTO = new VendorHistoryDTO() { Id = Id, Name = dto.Name, Title = dto.Title, Date = dto.Date, Tags = dto.Tags.Select(x => new TagDTO { Name = x.Name, Value = x.Value }).ToList() }; string json = JsonConvert.SerializeObject(vendorHistoryDTO); var historyList = new List <History>(); var history = new History() { VendorId = Id, Operation = "Post", JsonResult = json, }; historyList.Add(history); var vendor = new Vendor() { Id = Id, Name = dto.Name, Title = dto.Title, Date = dto.Date, Tags = tagList, Histories = historyList }; var vendorResult = await _repository.Insert(vendor); VendorInsertResponseDTO vendorResponseDTO = new VendorInsertResponseDTO() { Id = vendorResult.Id, Name = vendorResult.Name, Title = vendorResult.Title, Date = vendorResult.Date, Tags = vendorResult.Tags.Select(x => new TagDTO { Name = x.Name, Value = x.Value }).ToList(), Histories = vendorResult.Histories.Select(y => new HistoryDTO { JsonResult = y.JsonResult, Operation = y.Operation, }).ToList() }; return(vendorResponseDTO); }
public async Task<IActionResult> Insert([FromBody] VendorInsertDTO dto) { var insertVendor = await _vendorService.Insert(dto); return Created(nameof(GetAllById), insertVendor); }