Esempio n. 1
0
 public IActionResult GetChemicalFamily([FromBody] dtoChemFamily name)
 {
     try {
         if (_context.ChemicalFamily.Any())
         {
             var chemFamily = _context.ChemicalFamily.Where(x => x.ChemicalName.ToLower() == name.ChemicalName.ToLower());
             return(new ObjectResult(chemFamily));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception e) {
         return(BadRequest($"Error: {e.InnerException}"));
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateChemicalFamily([FromBody] dtoChemFamily updateInfo)
        {
            try {
                if (_context.ChemicalFamily.Any())
                {
                    if (_context.ChemicalFamily.Any(x => x.ChemicalName.ToLower() == updateInfo.ChemicalName.ToLower()))
                    {
                        var chemFamSource = _context.ChemicalFamily.Where(x => x.ChemicalName.ToLower() == updateInfo.ChemicalName.ToLower()).FirstOrDefault();
                        chemFamSource.reorderThreshold = updateInfo.reorderThreshold;
                        chemFamSource.ReorderQuantity  = updateInfo.ReorderQuantity;

                        _context.ChemicalFamily.Update(chemFamSource);
                        await _context.SaveChangesAsync();

                        return(Ok(chemFamSource));
                    }
                }
                return(BadRequest());
            }
            catch (Exception e) {
                return(BadRequest($"Error: {e.InnerException}"));
            }
        }