/// <summary> /// Archives a Product by setting boolean IsArchived to true /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ServiceResponse <Product> > ArchieveProductAsync(int id) { try { var product = await _db.Products.FindAsync(id); product.IsArchived = true; await _db.SaveChangesAsync(); return(new ServiceResponse <Product> { Data = product, Time = DateTime.UtcNow, Message = "Archived Product", IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponse <Product> { Data = null, Time = DateTime.UtcNow, Message = ex.StackTrace, IsSuccess = false }); } }
public async Task <TEntity> Add(TEntity entity) { var result = _dbContext.Set <TEntity>().Add(entity); await _dbContext.SaveChangesAsync(); return(result.Entity); }
public ServiceResponse <Data.Model.Product> CreateProduct(Data.Model.Product product) { try { dbContext.Products.AddAsync(product); var newInventory = new ProductInventory { Product = product, QuantityOnHand = 0, IdealQuantity = 10, }; dbContext.ProductInventories.AddAsync(newInventory); dbContext.SaveChangesAsync(); return(new ServiceResponse <Data.Model.Product> { Data = product, Time = DateTime.UtcNow, Message = "Saved new product", isSuccess = true, }); } catch (System.Exception) { return(new ServiceResponse <Data.Model.Product> { Data = null, Time = DateTime.UtcNow, Message = "Error while saving new product", isSuccess = false, }); } }