Ejemplo n.º 1
0
        private void changeInventory(IInventoryEntity changeEntity, IAccountingEntity costEntity, IManagementService service)
        {
            Unit quan = new Unit();

            quan = (changeEntity is PowderQuantity) ? this.massUnits.OfType <Unit>().Where(u => u.Abbreviation == "mgr.").First() : this.primerService.GetQuantityUnits().OfType <Unit>().Where(u => u.Abbreviation == "ea.").First();

            if (changeEntity.QuantityUnitId != 0 && changeEntity.QuantityUnitId != quan.Id)
            {
                switch ((this.massUnits.OfType <Unit>().Where(u => u.Id == changeEntity.QuantityUnitId).First() as Unit).Abbreviation)
                {
                case "lbs.":
                    changeEntity.Change *= 7000000;
                    break;

                case "gr.":
                    changeEntity.Change *= 1000;
                    break;

                case "oz.":
                    changeEntity.Change *= 437500;
                    break;
                }
            }

            changeEntity.QuantityUnitId = quan.Id;
            changeEntity.StartQuantity  = changeEntity.EndQuantity;
            changeEntity.EndQuantity    = changeEntity.EndQuantity + changeEntity.Change;
            service.AddQuantity(changeEntity);

            var cost = Request.Form["Cost"];

            if (!String.IsNullOrEmpty(cost))
            {
                costEntity.EntityId       = changeEntity.EntityId;
                costEntity.Date           = changeEntity.Date;
                costEntity.Quantity       = changeEntity.Change;
                costEntity.QuantityUnitId = changeEntity.QuantityUnitId;
                costEntity.Cost           = Convert.ToDecimal(cost);
                service.AddCost(costEntity);
            }
        }