Ejemplo n.º 1
0
        /*
         * The DeleteProduct method uses the Model classes to delete data for an existing category in the database.
         */
        public ActionResult DeleteProduct(string ProductID, string CategoryID, string CategoryName)
        {
            Models.CatalogData cData = new Models.CatalogData();
            bool result = cData.DeleteProduct(ProductID);

            return(RedirectToAction("CategoryDetails", "Home", new { CategoryID = CategoryID, CategoryName = CategoryName, SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            List <string> statusChecks = checkStatus();

            ViewBag.DatabaseCheck = statusChecks[0];
            if (ViewBag.DatabaseCheck != "Success!")
            {
                return(RedirectToAction("Setup", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
            }
            getUserName();
            ViewBag.Title = "Categories";
            Models.CatalogData     cData                = new Models.CatalogData();
            List <Models.Category> categories           = cData.CategoryList();
            List <string>          categoryIDs          = new List <string>();
            List <string>          categoryNames        = new List <string>();
            List <string>          categoryDescriptions = new List <string>();
            List <string>          categoryImages       = new List <string>();

            foreach (Models.Category category in categories)
            {
                categoryIDs.Add(category.CategoryID);
                categoryNames.Add(category.CategoryName);
                categoryDescriptions.Add(category.CategoryDescription);
                categoryImages.Add(category.CategoryImageURL);
            }
            ViewBag.CategoryIDs          = categoryIDs;
            ViewBag.CategoryNames        = categoryNames;
            ViewBag.CategoryDescriptions = categoryDescriptions;
            ViewBag.CategoryImages       = categoryImages;
            return(View());
        }
Ejemplo n.º 3
0
        /*
         * The DeleteCategory method uses the Model classes to delete data for an existing category in the database.
         */
        public ActionResult DeleteCategory(string CategoryID)
        {
            Models.CatalogData cData = new Models.CatalogData();
            bool result = cData.DeleteCategory(CategoryID);

            return(RedirectToAction("Index", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
        }
Ejemplo n.º 4
0
        /*
         * The Approve method uses the Model classes to update data in the database.
         * It also calls the setApprovalStatus helper function to update the Proposals list in SharePoint.
         */
        public ActionResult Approve(string proposalID, string productID, string newPrice)
        {
            Models.CatalogData cData = new Models.CatalogData();
            bool success             = cData.UpdateProductPrice(productID, double.Parse(newPrice));

            if (success)
            {
                setApprovalStatus(proposalID);
            }
            return(RedirectToAction("Proposals", "Home", new { ProductID = productID, SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
        }
Ejemplo n.º 5
0
        public ActionResult CategoryDetails(string CategoryID, string CategoryName)
        {
            getUserName();
            ViewBag.Title = CategoryName;
            Models.CatalogData    cData               = new Models.CatalogData();
            List <Models.Product> products            = cData.ProductList(CategoryID);
            List <string>         productIDs          = new List <string>();
            List <string>         productNames        = new List <string>();
            List <decimal>        productPrices       = new List <decimal>();
            List <string>         productDescriptions = new List <string>();
            List <string>         productImages       = new List <string>();
            List <bool>           productHasWorkflow  = new List <bool>();

            foreach (Models.Product product in products)
            {
                productIDs.Add(product.ProductID);
                productNames.Add(product.ProductName);
                productPrices.Add(product.ProductPrice);
                productDescriptions.Add(product.ProductDescription);
                productImages.Add(product.ProductImageURL);
                productHasWorkflow.Add(DoesProductHaveProposal(product.ProductID));
            }
            ViewBag.CategoryID          = CategoryID;
            ViewBag.ProductIDs          = productIDs;
            ViewBag.ProductNames        = productNames;
            ViewBag.ProductPrices       = productPrices;
            ViewBag.ProductDescriptions = productDescriptions;
            ViewBag.ProductImages       = productImages;
            ViewBag.ProductHasWorkflow  = productHasWorkflow;
            if (productIDs.Count > 0)
            {
                ViewBag.Message = "Click a product to view details";
            }
            else
            {
                ViewBag.Message = "This category contains no products. You can add new products from here.";
            }

            return(View());
        }
Ejemplo n.º 6
0
 public ActionResult SaveProduct(string CategoryID, string ProductID, string ProductName, string ProductPrice, string ProposedPrice, string ProductDescription, string ProductImageURL, string CategoryName)
 {
     getUserName();
     Models.CatalogData cData   = new Models.CatalogData();
     Models.Product     product = cData.UpdateProduct(CategoryID, ProductID, ProductName, ProductDescription, ProductImageURL);
     if (!string.IsNullOrEmpty(ProposedPrice))
     {
         string appUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
         if (appUrl.EndsWith(":444/"))
         {
             appUrl = appUrl.Replace(":444/", "/");
         }
         var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
         using (var appContext = spContext.CreateUserClientContextForSPAppWeb())
         {
             if (appContext != null)
             {
                 Web appWeb = appContext.Web;
                 appContext.Load(appWeb);
                 List proposalList = appWeb.Lists.GetByTitle("Proposals");
                 appContext.Load(proposalList);
                 appContext.ExecuteQuery();
                 ListItemCreationInformation itemInfo = new ListItemCreationInformation();
                 ListItem newProposal = proposalList.AddItem(itemInfo);
                 newProposal["Title"]          = ProductName + ": New Price Change Proposal";
                 newProposal["ProductID"]      = ProductID;
                 newProposal["ProductName"]    = ProductName;
                 newProposal["ExistingPrice"]  = ProductPrice;
                 newProposal["ProposedPrice"]  = ProposedPrice;
                 newProposal["ProposedBy"]     = ViewBag.UserName;
                 newProposal["Status"]         = "Pending";
                 newProposal["ApproversAlias"] = ownersGroupAlias;
                 newProposal["AppURL"]         = appUrl;
                 newProposal.Update();
                 appContext.ExecuteQuery();
             }
         }
     }
     return(RedirectToAction("CategoryDetails", "Home", new { CategoryID = CategoryID, CategoryName = CategoryName, SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
 }
Ejemplo n.º 7
0
 public ActionResult CreateProduct(string CategoryID, string ProductName, string ProductDescription, string ProductImageURL, string CategoryName)
 {
     Models.CatalogData cData   = new Models.CatalogData();
     Models.Product     product = cData.AddProduct(CategoryID, ProductName, ProductDescription, ProductImageURL);
     return(RedirectToAction("CategoryDetails", "Home", new { CategoryID = CategoryID, CategoryName = CategoryName, SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
 }
Ejemplo n.º 8
0
 public ActionResult SaveCategory(string CategoryID, string CategoryName, string CategoryDescription, string CategoryImageURL)
 {
     Models.CatalogData cData    = new Models.CatalogData();
     Models.Category    category = cData.UpdateCategory(CategoryID, CategoryName, CategoryDescription, CategoryImageURL);
     return(RedirectToAction("Index", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri }));
 }