public async Task <ActionResult <ShootingSession> > PostShootingSession(ShootingSession shootingSession) { _context.ShootingSession.Add(shootingSession); await _context.SaveChangesAsync(); return(CreatedAtAction("GetShootingSession", new { id = shootingSession.Id }, shootingSession)); }
public async Task <IActionResult> PutShootingSession(int id, ShootingSession shootingSession) { if (id != shootingSession.Id) { return(BadRequest()); } _context.Entry(shootingSession).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShootingSessionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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 Edit([Bind(Include = "Id,Date,LocationId,GunId,CartridgeId,Rounds,Retention,Notes")] ShootingSession modEntity) { if (ModelState.IsValid) { this.service.Edit(modEntity); 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)); }