public async Task <ActionResult <CartridgeLoad> > PostCartridgeLoad(CartridgeLoad cartridgeLoad)
        {
            _context.CartridgeLoad.Add(cartridgeLoad);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCartridgeLoad", new { id = cartridgeLoad.Id }, cartridgeLoad));
        }
        public async Task <IActionResult> PutCartridgeLoad(int id, CartridgeLoad cartridgeLoad)
        {
            if (id != cartridgeLoad.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cartridgeLoad).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartridgeLoadExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public ActionResult EditLoad([Bind(Include = "Id,Name,CaliberId,BulletId,PowderId,PowderWeight,PowderWeightUnitId,COL,COLUnitId,Velocity,VelocityUnitId,Pressure,PressureUnitId,Notes")] CartridgeLoad entity)
        {
            if (ModelState.IsValid)
            {
                var weight = Convert.ToDecimal(Request.Form["Weight"]) * 1000m;

                entity.PowderWeight = (int)weight;
                this.cartridgeLoadService.Edit(entity);
                return(RedirectToAction("LoadIndex", new { id = entity.CaliberId }));
            }

            Caliber caliber = this.cartridgeLoadService.GetCalibers().Where(c => c.Id == (int)entity.CaliberId).First();

            ViewBag.CaliberId          = caliber;
            ViewBag.BulletId           = new SelectList(this.bulletViews, "BulletId", "BulletName", entity.BulletId);
            ViewBag.PowderId           = new SelectList(this.powderViews, "Id", "Name", entity.PowderId);
            ViewBag.PowderWeight       = (decimal)entity.PowderWeight / 1000m;
            ViewBag.PowderWeightUnitId = new SelectList(this.massUnits.OfType <Unit>().Where(u => u.Abbreviation == "gr."), "Id", "Abbreviation", entity.PowderWeightUnitId);
            ViewBag.COL            = entity.COL;
            ViewBag.COLUnitId      = new SelectList(this.lengthUnits, "Id", "Abbreviation", entity.COLUnitId);
            ViewBag.Velocity       = entity.Velocity;
            ViewBag.VelocityUnitId = new SelectList(this.velocityUnits, "Id", "Abbreviation", entity.VelocityUnitId);
            ViewBag.Pressure       = entity.Pressure;
            ViewBag.PressureUnitId = new SelectList(this.pressureUnits, "Id", "Abbreviation", entity.PressureUnitId);
            ViewBag.Notes          = entity.Notes;

            return(View(entity));
        }
Пример #4
0
        protected bool addFactoryCartridge(Brass brass, Bullet bullet, CartridgeLoad cartridgeLoad, bool addToStore)
        {
            try
            {
                using (var transaction = new TransactionScope())
                {
                    int brassId;
                    if (this.brasses.OfType <Brass>().Where(b => b.CaliberId == brass.CaliberId && b.ManufacturerId == brass.ManufacturerId && b.MaterialId == brass.MaterialId && brass.TimesFired == 0).Any())
                    {
                        var existingBrass = this.brasses.OfType <Brass>().Where(b => b.CaliberId == brass.CaliberId && b.ManufacturerId == brass.ManufacturerId && b.MaterialId == brass.MaterialId && b.TimesFired == 0).First();
                        brassId = existingBrass.Id;
                    }
                    else
                    {
                        brass.TimesFired = 0;
                        brassId          = this.brassService.Add(brass);
                    }

                    Bullet existingBullet;
                    int    bulletId;
                    var    calDiameter = this.calibers.OfType <Caliber>().Where(c => c.Id == brass.CaliberId).First();
                    bullet.Diameter = calDiameter.Diameter;
                    if (this.bullets.OfType <Bullet>().Where(b => b.Diameter == bullet.Diameter && b.ManufacturerId == bullet.ManufacturerId && b.MaterialId == bullet.MaterialId && b.Mass == bullet.Mass).Any())
                    {
                        existingBullet = this.bullets.OfType <Bullet>().Where(b => b.Diameter == bullet.Diameter && b.ManufacturerId == bullet.ManufacturerId && b.MaterialId == bullet.MaterialId && b.Mass == bullet.Mass).First();
                        bulletId       = existingBullet.Id;
                    }
                    else
                    {
                        bullet.DiameterUnitId = calDiameter.DiameterUnitId;
                        bulletId = this.bulletService.Add(bullet);
                    }

                    cartridgeLoad.BulletId = bulletId;
                    var cartridgeLoadId = this.cartridgeLoadService.Add(cartridgeLoad);

                    var cartridge = new Cartridge
                    {
                        CartridgeLoadId = cartridgeLoadId,
                        BrassId         = brassId,
                        ManufacturerId  = brass.ManufacturerId
                    };
                    var cartridgeId = this.cartridgeService.Add(cartridge);

                    if (addToStore)
                    {
                    }

                    transaction.Complete();
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #5
0
        public ActionResult FactoryCartridge([Bind(Include = "Id,Name,CaliberId,MassUnitId,BulletTypeId,ManufacturerId,COLUnitId,PressureUnitId,VelocityUnitId,BrassMaterialId,BulletMaterialId,ManufacturerId,Notes")] Cartridge entity)
        {
            var brass         = new Brass();
            var bullet        = new Bullet();
            var cartridgeLoad = new CartridgeLoad();

            //brass.Name = entity.Name;
            bullet.Name             = entity.Name;
            cartridgeLoad.Name      = entity.Name;
            brass.CaliberId         = Convert.ToInt32(Request.Form["CaliberId"]);
            cartridgeLoad.CaliberId = Convert.ToInt32(Request.Form["CaliberId"]);
            cartridgeLoad.COL       = Convert.ToDecimal(Request.Form["COL"]);
            cartridgeLoad.COLUnitId = Convert.ToInt32(Request.Form["COLUnitId"]);
            if (!String.IsNullOrEmpty(Request.Form["Velocity"]))
            {
                cartridgeLoad.Velocity       = Convert.ToInt32(Request.Form["Velocity"]);
                cartridgeLoad.VelocityUnitId = Convert.ToInt32(Request.Form["VelocityUnitId"]);
            }
            if (!String.IsNullOrEmpty(Request.Form["Pressure"]))
            {
                cartridgeLoad.Pressure       = Convert.ToInt32(Request.Form["Pressure"]);
                cartridgeLoad.PressureUnitId = Convert.ToInt32(Request.Form["PressureUnitId"]);
            }
            bullet.BulletTypeId   = Convert.ToInt32(Request.Form["BulletTypeId"]);
            brass.MaterialId      = Convert.ToInt32(Request.Form["BrassMaterialId"]);
            bullet.MaterialId     = Convert.ToInt32(Request.Form["BulletMaterialId"]);
            bullet.Mass           = Convert.ToInt32(Request.Form["Mass"]);
            bullet.MassUnitId     = Convert.ToInt32(Request.Form["MassUnitId"]);
            brass.ManufacturerId  = entity.ManufacturerId;
            bullet.ManufacturerId = entity.ManufacturerId;

            if (addFactoryCartridge(brass, bullet, cartridgeLoad, Request.Form["Quantity"] == String.Empty))
            {
                return(RedirectToAction("CartridgeIndex"));
            }
            else
            {
                ViewBag.CaliberId      = new SelectList(this.calibers, "Id", "Name");
                ViewBag.MassUnitId     = new SelectList(this.massUnits, "Id", "Abbreviation");
                ViewBag.BulletTypeId   = new SelectList(this.bulletTypes, "Id", "Abbreviation");
                ViewBag.ManufacturerId = new SelectList(this.manufacturers, "Id", "Name");

                return(View());
            }
        }