Exemplo n.º 1
0
        public async Task <IActionResult> PutDrug(long id, Drug drug)
        {
            if (id != drug.Id)
            {
                return(BadRequest());
            }

            var existingdrug = await _context.Drugs.FindAsync(id);

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

            //trying to restore a drug
            if (existingdrug.Deleted && !drug.Deleted)
            {
                return(BadRequest("Cannot restore a drug"));
            }

            _context.Entry(existingdrug).State = EntityState.Detached;

            _context.Entry(drug).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Drug> > DeleteDrug(long id)
        {
            var drug = await _drugContext.Drugs.FindAsync(id);

            drug.Deleted = true;

            _drugContext.Entry(drug).State = EntityState.Modified;

            await _drugContext.SaveChangesAsync();

            return(drug);
        }