public IHttpActionResult PostInventoryCountHistory(InventoryCountHistory inventoryCountHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.InventoryCountHistories.Add(inventoryCountHistory); try { db.SaveChanges(); } catch (DbUpdateException) { if (InventoryCountHistoryExists(inventoryCountHistory.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = inventoryCountHistory.Id }, inventoryCountHistory)); }
public IHttpActionResult PutInventoryCountHistory(int id, InventoryCountHistory inventoryCountHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventoryCountHistory.Id) { return(BadRequest()); } db.Entry(inventoryCountHistory).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InventoryCountHistoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetInventoryCountHistory(int id) { InventoryCountHistory inventoryCountHistory = db.InventoryCountHistories.Find(id); if (inventoryCountHistory == null) { return(NotFound()); } return(Ok(inventoryCountHistory)); }
public async void CreateInventoryCountMethod() { //we make sure that we have selected a location to count if (SelectedLocation != null) { //now we make a new inventoryCount from that location and we then put it in the database InventoryCount ic = new InventoryCount(SelectedLocation); await _inventoryCountCatalog.Create(ic); //now we take that IC out again, to make sure we are working with the right id's InventoryCount ic2 = Catalog <InventoryCount> .Instance.GetList.FindLast(x => x.Location == SelectedLocation.Id && x.DateCounted >= DateTime.Now.Subtract(TimeSpan.FromSeconds(10))); //here we freeze that inventoryCount in our history class InventoryCountHistory ich = new InventoryCountHistory(ic2); await Catalog <InventoryCountHistory> .Instance.Create(ich); //We go though all the data provided by the user and checking its counted to something above 0 //this bool is for checking that data is inserted relative to the inventoryCount bool gotData = false; foreach (var i in _listForProducts) { int totalAmount = (i.BoxAmount * i.Product.AmountPerBox) + i.Amount; if (totalAmount > 0) { //here we then create a "data" row for that specific product and inventoryCount //and store it in the database InventoryCountProduct icp = new InventoryCountProduct(ic2.Id, i.Product.Id, totalAmount); await Catalog <InventoryCountProduct> .Instance.Create(icp); //we then make a frozen copy of that inventoryCount "data" and throw it in the history database InventoryCountHistoryData ichd = new InventoryCountHistoryData(ich.Id, i.Product.Name, icp.Amount, i.Product.AmountPerBox); ichd.Id = Catalog <InventoryCountProduct> .Instance.GetList. Find(x => x.InventoryCount == ic2.Id && x.Product == icp.Product).Id; await Catalog <InventoryCountHistoryData> .Instance.Create(ichd); gotData = true; } } //if no inventoryCountProduct / inventoryCountHistoryData is provided, both the inventoryCount and the record of it is deleted if (!gotData) { await Catalog <InventoryCount> .Instance.Delete(ic2.Id); await Catalog <InventoryCountHistory> .Instance.Delete(ich.Id); } OnPropertyChanged(nameof(InventoryCountHistoriesCatalog)); } }
public IHttpActionResult DeleteInventoryCountHistory(int id) { InventoryCountHistory inventoryCountHistory = db.InventoryCountHistories.Find(id); if (inventoryCountHistory == null) { return(NotFound()); } db.InventoryCountHistories.Remove(inventoryCountHistory); db.SaveChanges(); return(Ok(inventoryCountHistory)); }