public IHttpActionResult PostInventoryCountHistoryData(InventoryCountHistoryData inventoryCountHistoryData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.InventoryCountHistoryDatas.Add(inventoryCountHistoryData); try { db.SaveChanges(); } catch (DbUpdateException) { if (InventoryCountHistoryDataExists(inventoryCountHistoryData.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = inventoryCountHistoryData.Id }, inventoryCountHistoryData)); }
public IHttpActionResult PutInventoryCountHistoryData(int id, InventoryCountHistoryData inventoryCountHistoryData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventoryCountHistoryData.Id) { return(BadRequest()); } db.Entry(inventoryCountHistoryData).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InventoryCountHistoryDataExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetInventoryCountHistoryData(int id) { InventoryCountHistoryData inventoryCountHistoryData = db.InventoryCountHistoryDatas.Find(id); if (inventoryCountHistoryData == null) { return(NotFound()); } return(Ok(inventoryCountHistoryData)); }
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 DeleteInventoryCountHistoryData(int id) { InventoryCountHistoryData inventoryCountHistoryData = db.InventoryCountHistoryDatas.Find(id); if (inventoryCountHistoryData == null) { return(NotFound()); } db.InventoryCountHistoryDatas.Remove(inventoryCountHistoryData); db.SaveChanges(); return(Ok(inventoryCountHistoryData)); }