Пример #1
0
        public async Task <Guid> CreateAsync(SubItemPropertyDTO subItemPropertyDTO)
        {
            Guid id = Guid.NewGuid();
            await _context.SubItemProperty.AddAsync(new Data.Entities.SubItemProperty
            {
                Id          = id,
                SubItemId   = subItemPropertyDTO.SubItemId,
                Name        = subItemPropertyDTO.Name,
                Value       = subItemPropertyDTO.Value,
                Description = subItemPropertyDTO.Description,
                CreatedBy   = subItemPropertyDTO.CreatedBy,
                CreatedDate = DateTime.Now,
            });

            try
            {
                var response = await _context.SaveChangesAsync();

                if (response > 0)
                {
                    return(id);
                }
                else
                {
                    return(Guid.Empty);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("There was an exception when attempting to create a SubItemProperty.", ex);
                return(Guid.Empty);
            }
        }
        public async Task <ActionResult <SubItemPropertyDTO> > GetById(Guid id)
        {
            SubItemPropertyDTO subItemProperty = await _subItemPropertyService.GetByIdAsync(id);

            if (subItemProperty.Id == Guid.Empty)
            {
                return(NotFound());
            }

            return(Ok(subItemProperty));
        }
Пример #3
0
        public async IAsyncEnumerable <SubItemPropertyDTO> GetAllAsync()
        {
            await foreach (var subItemProperty in _context.SubItemProperty.AsAsyncEnumerable())
            {
                if (subItemProperty.DeletedDate is null)
                {
                    SubItemPropertyDTO subItemPropertyDTO = CloneSubItemPropertyEntity(subItemProperty);

                    yield return(subItemPropertyDTO);
                }
            }
        }
Пример #4
0
        public async IAsyncEnumerable <SubItemPropertyDTO> GetBySubItemAsync(Guid subItemId)
        {
            List <Data.Entities.SubItemProperty> subItemPropertyList = await _context.SubItemProperty.Where(a => a.SubItemId == subItemId).ToListAsync();

            foreach (var subItemProperty in subItemPropertyList)
            {
                if (subItemProperty.DeletedDate is null)
                {
                    SubItemPropertyDTO subItemPropertyDTO = CloneSubItemPropertyEntity(subItemProperty);

                    yield return(subItemPropertyDTO);
                }
            }
        }
        public async Task <ActionResult> Create([FromBody] SubItemPropertyDTO subItemPropertyDTO)
        {
            Guid id = await _subItemPropertyService.CreateAsync(subItemPropertyDTO);

            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));
        }
Пример #6
0
        public SubItemPropertyDTO CloneSubItemPropertyEntity(Data.Entities.SubItemProperty subItemProperty)
        {
            SubItemPropertyDTO subItemPropertyDTO = new SubItemPropertyDTO
            {
                Id          = subItemProperty.Id,
                SubItemId   = subItemProperty.SubItemId,
                Name        = subItemProperty.Name,
                Value       = subItemProperty.Value,
                Description = subItemProperty.Description,
                CreatedDate = subItemProperty.CreatedDate,
                CreatedBy   = subItemProperty.CreatedBy,
                UpdatedDate = subItemProperty.UpdatedDate,
                UpdatedBy   = subItemProperty.UpdatedBy,
                DeletedDate = subItemProperty.DeletedDate,
                DeletedBy   = subItemProperty.DeletedBy,
            };

            return(subItemPropertyDTO);
        }