Exemplo n.º 1
0
        public async Task DeleteDesign(int id)
        {
            DesignDto designdto = await GetDesign(id);

            Design design = await _context.Design.FirstOrDefaultAsync(d => d.Id == designdto.Id);

            _context.Entry(design).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
 public DesignBl(DesignDto dto)
 {
     if (dto != null)
     {
         Id       = dto.Id;
         Name     = dto.Name;
         Comment  = dto.Comment;
         Price    = dto.Price;
         PriceVip = dto.PriceVip;
     }
 }
Exemplo n.º 3
0
        public async Task <Design> UpdateDesign(int id, DesignDto incomingData)
        {
            Design design = await _context.Design.FirstOrDefaultAsync(x => x.Id == id);

            design.Title                 = incomingData.Title;
            design.DesignCoords          = incomingData.DesignCoords;
            _context.Entry(design).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _context.SaveChangesAsync();

            return(design);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PutDesign(int id, DesignDto incomingData)
        {
            if (id != incomingData.Id)
            {
                return(BadRequest());
            }

            var updatedDesign = await _design.UpdateDesign(id, incomingData);

            return(Ok(updatedDesign));
        }
Exemplo n.º 5
0
 public ActionResult <DesignDto> Add([FromBody] DesignDto dto)
 {
     try
     {
         var item = _bl.Add(dto);
         return(CreatedAtRoute("GetDesignById", new { Id = item.Id }, item));
     }
     catch (Exception ex)
     {
         return(Conflict($"{ex.Message}: {ex?.InnerException}"));
     }
 }
Exemplo n.º 6
0
        public DesignDto Add(DesignDto dto)
        {
            var item = new Design()
            {
                Name     = dto.Name,
                Comment  = dto.Comment,
                Price    = dto.Price,
                PriceVip = dto.PriceVip,
            };

            _dao.Create(item);
            return(_map(item));
        }
Exemplo n.º 7
0
 public ActionResult <DesignDto> Update([FromBody] DesignDto dto)
 {
     try
     {
         return(_bl.Update(dto));
     }
     catch (KeyNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(Conflict(ex.Message));
     }
 }
Exemplo n.º 8
0
        public async Task <Design> CreateDesign(DesignDto incomingData)
        {
            Design design = new Design
            {
                Id           = incomingData.Id,
                Title        = incomingData.Title,
                DesignCoords = incomingData.DesignCoords,
                TimeStamp    = DateTime.Now
            };

            _context.Entry(design).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            await _context.SaveChangesAsync();

            return(design);
        }
Exemplo n.º 9
0
        public DesignDto Update(DesignDto dto)
        {
            var item = _dao.Get(dto.Id);

            if (item == null)
            {
                throw new KeyNotFoundException();
            }

            item.Name     = dto.Name;
            item.Comment  = dto.Comment;
            item.Price    = dto.Price;
            item.PriceVip = dto.PriceVip;
            _dao.Update(item);

            return(_map(item));
        }
Exemplo n.º 10
0
 public DesignDto Update(DesignDto item)
 {
     return(Url.AppendPathSegment("Design")
            .PutJsonAsync(item).ReceiveJson <DesignDto>().Result);
 }
Exemplo n.º 11
0
        public async Task <ActionResult <Design> > PostDesign(DesignDto incomingData)
        {
            await _design.CreateDesign(incomingData);

            return(CreatedAtAction("GetDesign", new { id = incomingData.Id }, incomingData));
        }