public async Task <IActionResult> PutBrass(int id, Brass brass)
        {
            if (id != brass.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <ActionResult <Brass> > PostBrass(Brass brass)
        {
            _context.Brass.Add(brass);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBrass", new { id = brass.Id }, brass));
        }
Exemple #3
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);
            }
        }
        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 Create([Bind(Include = "Id,Name,CaliberId,ParentId,Length,LengthUnitId,MaterialId,ManufacturerId,TimesFired,Notes")] Brass modEntity)
        {
            if (ModelState.IsValid)
            {
                this.service.Add(modEntity);
                return(RedirectToAction("Index"));
            }

            ViewBag.CaliberId      = new SelectList(this.calibers, "Id", "Name", modEntity.CaliberId);
            ViewBag.ManufacturerId = new SelectList(this.manufacturers, "Id", "Name", modEntity.ManufacturerId);
            ViewBag.MaterialId     = new SelectList(this.materials, "Id", "Name", modEntity.MaterialId);
            ViewBag.LengthUnitId   = new SelectList(this.lengthUnits, "Id", "Abbreviation", modEntity.Caliber.BrassLengthUnitId);

            return(View(modEntity));
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Is the instrument a brass or string instrument : ");
            string InstrumentType = Console.ReadLine();

            Console.WriteLine("Enter The name of the instrument : ");
            string name = Console.ReadLine();

            Console.WriteLine("What is the cost of the instrument? : ");
            int Cost = Int32.Parse(Console.ReadLine());


            if (InstrumentType.ToLower() == "brass")
            {
                Console.WriteLine("What material is the instrument made of? : ");
                string Material = Console.ReadLine();

                Console.WriteLine("What kind of sound does the instrument make? : ");
                string SoundMaking = Console.ReadLine();

                Instrument I1 = new Brass(name, Cost, Material, SoundMaking);
                I1.DisplayInstrument();
            }


            if (InstrumentType.ToLower() == "string")
            {
                bool isbowed = true;
                Console.WriteLine("How many strings does the instrument have? : ");
                int numstrings = Int32.Parse(Console.ReadLine());

                Console.WriteLine("Is the instrument bowed? : ");
                string answer = Console.ReadLine();
                if (answer.ToLower() == "yes")
                {
                    isbowed = true;
                }
                if (answer.ToLower() == "no")
                {
                    isbowed = false;
                }


                Instrument I2 = new String_Instrument(name, Cost, isbowed, numstrings);
                I2.DisplayInstrument();
            }
        }
    public void SerializeObject(string filename)
    {
        /* Each overridden field, property, or type requires
         * an XmlAttributes object. */
        XmlAttributes attrs = new XmlAttributes();

        /* Create an XmlElementAttribute to override the
         * field that returns Instrument objects. The overridden field
         * returns Brass objects instead. */
        XmlElementAttribute attr = new XmlElementAttribute();

        attr.ElementName = "Brass";
        attr.Type        = typeof(Brass);

        // Add the element to the collection of elements.
        attrs.XmlElements.Add(attr);

        // Create the XmlAttributeOverrides object.
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

        /* Add the type of the class that contains the overridden
         * member and the XmlAttributes to override it with to the
         * XmlAttributeOverrides object. */
        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Create the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(filename);

        // Create the object that will be serialized.
        Orchestra band = new Orchestra();

        // Create an object of the derived type.
        Brass i = new Brass();

        i.Name     = "Trumpet";
        i.IsValved = true;
        Instrument[] myInstruments = { i };
        band.Instruments = myInstruments;

        // Serialize the object.
        s.Serialize(writer, band);
        writer.Close();
    }
        public int Clone(int id)
        {
            var brass    = this.FindById((int)id) as Brass;
            var newBrass = new Brass();

            newBrass.CaliberId = brass.CaliberId;
            //newBrass.Length = brass.Length;
            //newBrass.LengthUnitId = brass.LengthUnitId;
            newBrass.ManufacturerId = brass.ManufacturerId;
            newBrass.MaterialId     = brass.MaterialId;
            newBrass.Name           = brass.Name;
            newBrass.Notes          = brass.Notes;
            newBrass.ParentId       = brass.Id;
            newBrass.TimesFired     = brass.TimesFired + 1;

            return(this.Add(newBrass));
        }
Exemple #9
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());
            }
        }
        static void Main(string[] args)
        {
            IDummy d = new Dumb();

            d.Print();
            d.Print(4);
            d.Print("Hello");
            Console.WriteLine("------------------------------------------------------------------------------------------------------------");
            D b = new ClassB();

            M1(b);
            M2(b);
            M3(b);
            M4(b);
            ClassAbstract c = new ClassB();

            c.PrintMe();
            //GC.Collect();
            //GC.WaitForPendingFinalizers();


            IFastFood f = new Sandwich();

            f.FastFood();
            Console.WriteLine("------------------------------------------------------------------------------------------------------------");
            Sandwich a = new Sandwich();

            a.FastFood();

            Console.WriteLine("------------------------------------------------------------------------------------------------------------");
            IPlayableInstrument[] orchestra = new IPlayableInstrument[5];
            int i = 0;

            orchestra[i++] = new Wind();
            orchestra[i++] = new Percussion();
            orchestra[i++] = new Stringed();
            orchestra[i++] = new Brass();
            orchestra[i++] = new Woodwind();
            TuneAll(orchestra);
        }
Exemple #11
0
    public void SerializeObject(string filename)
    {
        // To write the file, a TextWriter is required.
        TextWriter writer = new StreamWriter(filename);

        XmlAttributeOverrides attrOverrides =
            new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that overrides the Instrument type.
        XmlElementAttribute attr = new
                                   XmlElementAttribute(typeof(Brass));

        attr.ElementName = "Brass";

        // Adds the element to the collection of elements.
        attrs.XmlElements.Add(attr);
        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        // Creates the object to serialize.
        Orchestra band = new Orchestra();

        // Creates an object of the derived type.
        Brass i = new Brass();

        i.Name     = "Trumpet";
        i.IsValved = true;
        Instrument[] myInstruments = { i };
        band.Instruments = myInstruments;
        s.Serialize(writer, band);
        writer.Close();
    }