public ActionResult ChangeBrass([Bind(Include = "EntityId,InventoryTypeId,EndQuantity,Change,Date")] BrassQuantity entity) { if (ModelState.IsValid) { //entity.StartQuantity = Convert.ToInt32(((ServiceBase)this.brassService).GetQuantity(entity.EntityId)); //entity.EndQuantity = entity.StartQuantity + entity.Change; //var quan = this.quantityUnits.First() as Unit; //entity.QuantityUnitId = quan.Id; //((ServiceBase)this.brassService).AddQuantity(entity); //var cost = Request.Form["Cost"]; //if (!String.IsNullOrEmpty(cost)) //{ // var entityCost = new BrassCost(); // entityCost.EntityId = entity.EntityId; // entityCost.Date = entity.Date; // entityCost.Quantity = entity.Change; // entityCost.QuantityUnitId = entity.QuantityUnitId; // entityCost.Cost = Convert.ToDecimal(cost); // ((ServiceBase)this.brassService).AddCost(entityCost); //} this.changeInventory(entity, new BrassCost(), this.brassService); return(RedirectToAction("BrassIndex")); } var brasses = from brass in this.brassService.GetBrassViews() where !(from q in this.brassService.GetAllQuantities().OfType <BrassQuantity>() select q.EntityId).Contains(brass.Id) select brass; ViewBag.EntityId = new SelectList(brasses, "BrassId", "BrassFullName"); return(View()); }
public ActionResult Create([Bind(Include = "Id,Date,LocationId,GunId,CartridgeId,Rounds,Retention,Notes")] ShootingSession modEntity) { if (ModelState.IsValid) { using (var transaction = new TransactionScope()) { this.service.Add(modEntity); var cartQuantity = new CartridgeQuantity(); cartQuantity.EntityId = modEntity.CartridgeId; cartQuantity.Change = modEntity.Rounds * -1; cartQuantity.Date = modEntity.Date; cartQuantity.StartQuantity = (int)this.cartridgeService.GetQuantity(modEntity.CartridgeId); cartQuantity.EndQuantity = cartQuantity.StartQuantity + cartQuantity.Change; cartQuantity.QuantityUnitId = this.quantityUnits.OfType <Unit>().Where(u => u.Abbreviation == "ea.").First().Id; cartQuantity.InventoryTypeId = this.inventoryTypes.Where(i => i.Description == "Shooting").First().Id; this.cartridgeService.AddQuantity(cartQuantity); if (!(modEntity.Retention == null)) { var brassQuantity = new BrassQuantity(); var cart = this.cartridgeService.FindById(modEntity.CartridgeId) as Cartridge; var brass = this.brassService.FindById(cart.BrassId) as Brass; var nFiredBrassCollection = this.brasses.OfType <Brass>().Where(b => b.ParentId == brass.Id && b.Id != b.ParentId); var nFiredBrass = new Brass(); if (nFiredBrassCollection.Count() == 0) { var newId = this.brassService.Clone(brass.Id); nFiredBrass = this.brassService.FindById(newId) as Brass; } else { nFiredBrass = nFiredBrassCollection.First(); } brassQuantity.EntityId = nFiredBrass.Id; brassQuantity.Change = (int)modEntity.Retention; brassQuantity.Date = modEntity.Date; brassQuantity.StartQuantity = (int)this.brassService.GetQuantity(nFiredBrass.Id); brassQuantity.EndQuantity = brassQuantity.StartQuantity + brassQuantity.Change; brassQuantity.QuantityUnitId = this.quantityUnits.OfType <Unit>().Where(u => u.Abbreviation == "ea.").First().Id; brassQuantity.InventoryTypeId = this.inventoryTypes.Where(i => i.Description == "Recycle").First().Id; this.brassService.AddQuantity(brassQuantity); } transaction.Complete(); return(RedirectToAction("Index")); } } ViewBag.LocationId = new SelectList(this.shootingLocationViews, "Id", "ShootingLocationName", modEntity.LocationId); ViewBag.GunId = new SelectList(this.gunViews, "Id", "GunName", modEntity.GunId); ViewBag.CartridgeId = new SelectList(this.cartridgeViews, "Id", "CartridgeName", modEntity.CartridgeId); return(View(modEntity)); }
public ActionResult ChangeCartridge([Bind(Include = "EntityId,InventoryTypeId,EndQuantity,Change,Date")] CartridgeQuantity entity) { if (ModelState.IsValid) { var cost = Request.Form["Cost"]; if (!String.IsNullOrEmpty(cost)) { this.changeInventory(entity, new CartridgeCost(), this.cartridgeService); return(RedirectToAction("CartridgeIndex")); } using (var transaction = new TransactionScope()) { try { var cartridgeColl = from cartridge in this.cartridgeService.GetAll().OfType <Cartridge>() where cartridge.Id == entity.EntityId select cartridge; var singleCartridge = cartridgeColl.First(); var quan = this.cartridgeService.GetQuantityUnits().OfType <Unit>().Where(u => u.Abbreviation == "ea.").First(); var negChange = entity.Change * -1; entity.QuantityUnitId = quan.Id; entity.StartQuantity = entity.EndQuantity; entity.EndQuantity = entity.EndQuantity + entity.Change; this.cartridgeService.AddQuantity(entity); var brassQ = this.brassService.GetAllQuantities().OfType <BrassQuantity>().Where(b => b.EntityId == singleCartridge.BrassId).OrderByDescending(b => b.Date).First(); var newBrassQ = new BrassQuantity(); newBrassQ.EntityId = brassQ.EntityId; newBrassQ.Date = entity.Date; newBrassQ.Change = negChange; newBrassQ.InventoryTypeId = entity.InventoryTypeId; newBrassQ.StartQuantity = brassQ.EndQuantity; newBrassQ.EndQuantity = (brassQ.EndQuantity - entity.Change); newBrassQ.QuantityUnitId = quan.Id; this.brassService.AddQuantity(newBrassQ); var bulletQ = this.bulletService.GetAllQuantities().OfType <BulletQuantity>().Where(b => b.EntityId == singleCartridge.CartridgeLoad.BulletId).OrderByDescending(b => b.Date).First(); var newBulletQ = new BulletQuantity(); newBulletQ.EntityId = bulletQ.EntityId; newBulletQ.Date = entity.Date; newBulletQ.Change = negChange; newBulletQ.InventoryTypeId = entity.InventoryTypeId; newBulletQ.StartQuantity = bulletQ.EndQuantity; newBulletQ.EndQuantity = (bulletQ.EndQuantity - entity.Change); newBulletQ.QuantityUnitId = quan.Id; this.bulletService.AddQuantity(newBulletQ); var primerQ = this.primerService.GetAllQuantities().OfType <PrimerQuantity>().Where(p => p.EntityId == singleCartridge.PrimerId).OrderByDescending(p => p.Date).First(); var newPrimerQ = new PrimerQuantity(); newPrimerQ.EntityId = primerQ.EntityId; newPrimerQ.Date = entity.Date; newPrimerQ.Change = negChange; newPrimerQ.InventoryTypeId = entity.InventoryTypeId; newPrimerQ.StartQuantity = primerQ.EndQuantity; newPrimerQ.EndQuantity = (primerQ.EndQuantity - entity.Change); newPrimerQ.QuantityUnitId = quan.Id; this.primerService.AddQuantity(newPrimerQ); var powderQ = this.powderService.GetAllQuantities().OfType <PowderQuantity>().Where(p => p.EntityId == singleCartridge.CartridgeLoad.PowderId).OrderByDescending(p => p.Date).First(); var cartridgeLoad = this.cartridgeLoadService.GetAll().OfType <CartridgeLoad>().Where(c => c.Id == singleCartridge.CartridgeLoad.Id).First(); var powderChange = (int)(entity.Change * cartridgeLoad.PowderWeight); var newPowderQ = new PowderQuantity(); newPowderQ.EntityId = powderQ.EntityId; newPowderQ.Date = entity.Date; newPowderQ.Change = powderChange * -1; newPowderQ.InventoryTypeId = entity.InventoryTypeId; newPowderQ.StartQuantity = powderQ.EndQuantity; newPowderQ.EndQuantity = (powderQ.EndQuantity - powderChange); newPowderQ.QuantityUnitId = powderQ.QuantityUnitId; this.powderService.AddQuantity(newPowderQ); transaction.Complete(); } catch { } } return(RedirectToAction("CartridgeIndex")); } var finalEntities = this.cartridgeService.GetAllQuantityViewsWithNoInventory(); ViewBag.EntityId = new SelectList(finalEntities, "Id", "CartridgeName"); ViewBag.InventoryTypeId = new SelectList(this.inventoryTypes, "Id", "Description"); ViewBag.BrassId = new SelectList(this.brassViews, "Id", "BrassName"); ViewBag.PrimerId = new SelectList(this.primerViews, "Id", "PrimerName"); return(View()); }