public async Task <Guid> CreateAsync(SubItemDTO subItemDTO) { Guid id = Guid.NewGuid(); await _subItemContext.SubItem.AddAsync(new Data.Entities.SubItem { Id = id, CreatedDate = DateTime.Now, CreatedBy = subItemDTO.CreatedBy, }); try { var response = await _subItemContext.SaveChangesAsync(); if (response > 0) { return(id); } else { return(Guid.Empty); } } catch (Exception ex) { _logger.LogError("There was an exception when attempting to create a SubItem.", ex); return(Guid.Empty); } }
public async Task <ActionResult> Create([FromBody] SubItemDTO subItemDTO) { Guid id = await _subItemService.CreateAsync(subItemDTO); if (id == Guid.Empty) { return(StatusCode(303)); } return(Created( new Uri( string.Concat(Request.Path.ToString().Remove(Request.Path.ToString().Length - 6, 6), $"GetById/{id}"), UriKind.Relative), id)); }
public async IAsyncEnumerable <SubItemDTO> CloneSubItemEntity(Data.Entities.SubItem subItem, IAsyncEnumerable <SubItemPropertyDTO> subItemPropertyDTOList) { List <SubItemPropertyDTO> subItemPropertyList = new List <SubItemPropertyDTO>(); await foreach (var subItemProperty in subItemPropertyDTOList) { subItemPropertyList.Add(subItemProperty); } ; SubItemDTO subItemDTO = new SubItemDTO { Id = subItem.Id, SubItemPropertyList = subItemPropertyList, CreatedDate = subItem.CreatedDate, CreatedBy = subItem.CreatedBy, UpdatedDate = subItem.UpdatedDate, UpdatedBy = subItem.UpdatedBy, DeletedDate = subItem.DeletedDate, DeletedBy = subItem.DeletedBy, }; yield return(subItemDTO); }