/// <summary> /// create a new customer; criando cliente /// </summary> /// <param name="customer"></param> /// <returns></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSucess = true, Message = " New record add", Time = DateTime.Now, Data = customer }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { IsSucess = false, Message = ex.StackTrace, Time = DateTime.Now, Data = customer }); throw; } }
/// <summary> /// updates number of units aalable of the provided product /// </summary> /// <param name="id">productid</param> /// <param name="adjustment"> number of units added/ removed from inventory</param> /// <returns></returns> public ServiceResponse <ProductInventory> UpdatedUnitsAvailable(int id, int adjustment) { try { var inventory = _db.ProductInventorys.Include(inv => inv.Product) .First(inv => inv.Product.Id == id); inventory.QuantityOnHand += adjustment; try { CreateSnapshot(inventory); } catch (Exception e) { _logger.LogError(" Error creating iventory snapshot"); _logger.LogError(e.StackTrace); } _db.SaveChanges(); return(new ServiceResponse <ProductInventory> { IsSucess = true, Message = " Product Iventory adjusted", Time = DateTime.Now, Data = inventory }); } catch (Exception ex) { return(new ServiceResponse <ProductInventory> { IsSucess = false, Message = ex.StackTrace, Time = DateTime.Now, Data = null }); } }