示例#1
0
 public Catalog UpdateElement(CatalogNewDto newItem, Catalog entity)
 {
     entity.Id       = newItem.Id;
     entity.Name     = newItem.Name;
     entity.FatherId = newItem.FatherId;
     return(entity);
 }
示例#2
0
        public async Task <dynamic> CreateAsync(CatalogNewDto newItem)
        {
            var entity = _mapper.NewElement(newItem);
            await _context.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(new { Id = entity.Id });
        }
示例#3
0
        public async Task <dynamic> UpdateByIdAsync(string id, CatalogNewDto newItem)
        {
            var entity = await _context.Catalogs.FindAsync(id);

            if (entity == null)
            {
                return(null);
            }

            _context.Update(_mapper.UpdateElement(newItem, entity));
            await _context.SaveChangesAsync();

            return(new { Id = id });
        }
示例#4
0
        public async Task <ActionResult <CatalogDetailsDto> > CreateAsync([FromBody] CatalogNewDto newItem, string authentication)
        {
            bool check = await _authentication.IsLoginAsync(authentication);

            if (check)
            {
                var result = await _service.CreateAsync(newItem);

                if (result == null)
                {
                    return(NotFound());
                }

                return(CreatedAtAction(nameof(GetByIdAsync), new { id = result.Id }, result));;
            }
            return(BadRequest("Not Loggin"));
        }
示例#5
0
 public Catalog NewElement(CatalogNewDto dto) => new Catalog()
 {
     Id       = dto.Id,
     Name     = dto.Name,
     FatherId = dto.FatherId
 };