public ActionResult Create([Bind(Exclude = "ProductImage")]Product product, HttpPostedFileBase ProductImage, string returnUrl)
        {
            if (product.ProductInitialOrderQuantity == null)
            {
                product.ProductInitialOrderQuantity = (decimal?)0;
            }
            if (product.ProductGatewayCDIMinumumOrder == null)
            {
                product.ProductGatewayCDIMinumumOrder = (decimal?)0;
            }
            if (ModelState.IsValid)
            {
                // Get product's campaign and loop though that campaigns, companies price tiers
                Campaign thisCampaign = db.Campaigns.Where(c => c.CampaignID == product.CampaignID).FirstOrDefault();
                foreach (var tier in thisCampaign.Company.PricingTiers.Where(p => p.PricingTierStatus != MyExtensions.GetEnumDescription(Status.Archived)))
                {
                    // Create a new sell price for each price tier and add to DB
                    ProductSellPrice newSellPrice = new ProductSellPrice(product, tier.PricingTierName, tier.PricingTierLevel, (decimal)thisCampaign.Company.CompanyDefaultMargin);
                    db.ProductSellPrices.Add(newSellPrice);

                    // Attach fees
                    foreach (var fee in tier.Fees.Where(f => f.FeeStatus != MyExtensions.GetEnumDescription(Status.Archived)))
                    {
                        Fee newFee = new Fee(fee.FeeNameID, newSellPrice, fee.FeeType, fee.FeeCalculation, fee.FeeDollarAmount, fee.FeeAmortizedCharge, fee.FeeAmortizedType, fee.FeePercent, fee.FeePercentType, fee.FeeID);
                        db.Fees.Add(newFee);
                    }
                }

                // Loop though Attachment Types and add a ProductAttachmentType for each Attachment Type
                foreach (var attachmentType in db.AttachmentTypes.Where(a => a.Status != archived).OrderBy(a => a.TypeName))
                {
                    // Create a Product Attament type
                    ProductAttachmentType newProductAttachmentType = new ProductAttachmentType(product.ProductID, attachmentType.ID);
                    db.ProductAttachmentTypes.Add(newProductAttachmentType);
                }

                // Product Image
                if (ProductImage != null && ProductImage.ContentLength > 0)
                {
                    byte[] imageBinaryData = new byte[ProductImage.ContentLength];
                    int readresult = ProductImage.InputStream.Read(imageBinaryData, 0, ProductImage.ContentLength);
                    product.ProductImage = imageBinaryData;
                    product.ProductImageType = ProductImage.ContentType;
                }

                // Add Audit Entry
                AuditTrail audit = new AuditTrail(DateTime.Now, User.Identity.Name, product, product.ProductID, "Create");
                db.AuditTrails.Add(audit);

                db.Products.Add(product);
                db.SaveChanges();

                if (returnUrl == null)
                {
                    return RedirectToAction("Index");
                }
                return RedirectToAction("Edit", new { id = product.ProductID, ReturnUrl = returnUrl });
            }

            // Sets Viewbag data for dropdowns
            SetViewBagData(returnUrl, product);

            return View(product);
        }
Ejemplo n.º 2
0
        // Fee
        public AuditTrail(DateTime dateTime, string userName, Fee fee, int id, string comment)
        {
            this.AuditTrailTimeStamp = dateTime;
            this.AuditTrailUserName = userName;
            this.AuditTrailComment = comment;

            if(id > 0)
            {
                this.FeeID = id;
            }
            else
            {
                this.Fee = fee;
            }
        }
Ejemplo n.º 3
0
        //
        // GET: /Fee/Create
        public ActionResult Create(string returnUrl, int CompanyID = 0, int CampaignID = 0, int PricingTierID = 0, int ProductSellPriceID = 0)
        {
            ViewBag.ReturnUrl = returnUrl;
            InstantiateEmptyViewBagLists();

            // Generate Decoration method for member initialization
            Fee fee = new Fee();
            fee.OnCreate();

            return View(fee);
        }
Ejemplo n.º 4
0
        private void InstantiateFullViewBagLists(Fee fee)
        {
            // Company List
            var companyList = db.Companies.Where(c => c.CompanyStatus != archived);
            ViewBag.CompanyID = new SelectList(companyList, "CompanyID", "CompanyName", fee.CompanyID);

            // Pricing Tier List
            var pricingTierList = db.PricingTiers.Where(p => p.Company.CompanyStatus != archived &&
                                                                p.PricingTierStatus != archived);
            ViewBag.PricingTierID = new SelectList(pricingTierList, "PricingTierID", "PricingTierName", fee.PricingTierID);

            // Campaign List
            var campaignList = db.Campaigns.Where(c => c.CampaignStatus != archived &&
                                                        c.Company.CompanyStatus != archived);
            ViewBag.CampaignID = new SelectList(campaignList, "CampaignID", "CampaignName", fee.CampaignID);

            // Product List
            var productList = db.Products.Where(p => p.ProductStatus != archived &&
                                                        p.Campaign.CampaignStatus != archived &&
                                                        p.Campaign.Company.CompanyStatus != archived);
            ViewBag.ProductID = new SelectList(productList, "ProductID", "ProductName", fee.ProductID);

            // Sell Price List
            var sellPriceList = db.ProductSellPrices.Where(p => p.SellPriceStatus != archived &&
                                                                p.Product.ProductStatus != archived &&
                                                                p.Product.Campaign.CampaignStatus != archived &&
                                                                p.Product.Campaign.Company.CompanyStatus != archived);
            ViewBag.ProductSellPriceID = new SelectList(sellPriceList, "SellPriceID", "SellPriceName", fee.ProductSellPriceID);

            // Fee Name List
            ViewBag.FeeNameID = new SelectList(db.FeeNames.Where(f => f.FeeNameStatus != archived), "FeeNameID", "FeeNameName", fee.FeeNameID);
        }
Ejemplo n.º 5
0
        public ActionResult Edit(Fee fee, string returnUrl)
        {
            if(ModelState.IsValid)
            {
                var current = db.Fees.Find(fee.FeeID);
                db.Entry(current).CurrentValues.SetValues(fee);
                db.SaveChanges();

                if(returnUrl == null)
                {
                    return RedirectToAction("Index");
                }
                return Redirect(returnUrl);
            }

            ViewBag.ReturnUrl = returnUrl;
            InstantiateFullViewBagLists(fee);

            return View(fee);
        }
Ejemplo n.º 6
0
        public ActionResult Create(Fee fee, string returnUrl)
        {
            if(ModelState.IsValid)
            {
                db.Fees.Add(fee);
                db.SaveChanges();

                if(returnUrl == null)
                {
                    return RedirectToAction("Index");
                }
                return Redirect(returnUrl);
            }
            ViewBag.ReturnUrl = returnUrl;
            InstantiateFullViewBagLists(fee);

            return View(fee);
        }
Ejemplo n.º 7
0
 private void CalculateAmortizedFee(Fee fee)
 {
     // Determime the type of amortized fee and use the value associated
     if (fee.FeeAmortizedType == MyExtensions.GetEnumDescription(AmortizedTypeList.Annual_Sales_Projection))
     {
         fee.FeeDollarAmount = fee.FeeAmortizedCharge / _product.ProductAnnualSalesProjection;
     }
     else if (fee.FeeAmortizedType == MyExtensions.GetEnumDescription(AmortizedTypeList.GatewayCDI_Minimum_Order))
     {
         fee.FeeDollarAmount = fee.FeeAmortizedCharge / _product.ProductGatewayCDIMinumumOrder;
     }
     else if (fee.FeeAmortizedType == MyExtensions.GetEnumDescription(AmortizedTypeList.Initial_Order_Quantity))
     {
         fee.FeeDollarAmount = fee.FeeAmortizedCharge / _product.ProductInitialOrderQuantity;
     }
     else if (fee.FeeAmortizedType == MyExtensions.GetEnumDescription(AmortizedTypeList.Vendor_Minimum))
     {
         fee.FeeDollarAmount = fee.FeeAmortizedCharge / _product.ProductVendorMinimumOrder;
     }
 }