Exemplo n.º 1
0
        public void Post(UpdatePartSupplierModel model)
        {
            var request     = HttpContext.Current.Request;
            var authority   = request.Url.Authority;
            var spAppWebUrl = request.Headers["SPAppWebUrl"];
            var accessToken = request.Headers["X-SP-AccessToken"];

            using (var clientContext = TokenHelper.GetClientContextWithContextToken(spAppWebUrl, accessToken, authority))
            {
                var service = new PartSuppliersService(clientContext);
                service.UpdateSuppliers(model.Id, model.Suppliers.Select(s => s.CompanyName));
            }
        }
Exemplo n.º 2
0
        private void UpdateSuppliers(string country, string[] supplierNames)
        {
            var request      = HttpContext.Current.Request;
            var authority    = request.Url.Authority;
            var spAppWebUrl  = request.Headers["SPAppWebUrl"];
            var contextToken = request.Headers["SPContextToken"];

            using (var clientContext = TokenHelper.GetClientContextWithContextToken(
                       spAppWebUrl, contextToken, authority))
            {
                var service = new PartSuppliersService(clientContext);
                service.UpdateSuppliers(country, supplierNames);
            }
        }
Exemplo n.º 3
0
        public ActionResult StartWorkflow(int id, Guid workflowSubscriptionId, string spHostUrl)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            var webServiceUrl = Url.RouteUrl("DefaultApi", new { httproute = "", controller = "Data" }, Request.Url.Scheme);
            var payload       = new Dictionary <string, object>
            {
                { "appWebUrl", spContext.SPAppWebUrl.ToString() },
                { "webServiceUrl", webServiceUrl }
            };

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                var service = new PartSuppliersService(clientContext);
                service.StartWorkflow(workflowSubscriptionId, id, payload);
            }

            TempData["Message"] = "Workflow Successfully Started!";
            return(RedirectToAction("Details", new { id = id, SPHostUrl = spHostUrl }));
        }
Exemplo n.º 4
0
        public ActionResult Create(string country, string spHostUrl)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                var service = new PartSuppliersService(clientContext);
                var id      = service.GetIdByCountry(country);
                if (id == null)
                {
                    id = service.Add(country);
                    TempData["Message"] = "Part Supplier Successfully Created!";
                }
                else
                {
                    TempData["ErrorMessage"] = string.Format("Failed to Create The Part Supplier: There's already a Part Supplier who's country is {0}.", country);
                }

                return(RedirectToAction("Details", new { id = id.Value, SPHostUrl = spHostUrl }));
            }
        }
Exemplo n.º 5
0
        public ActionResult PublishSubmitEvent(int id, Guid workflowInstanceId, string spHostUrl)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                var service = new PartSuppliersService(clientContext);
                service.PublishCustomEvent(workflowInstanceId, "Submit for Approval", "");

                // Wait until workflow user status changed
                WorkflowInstance instance;
                do
                {
                    Thread.Sleep(1000);
                    instance = service.GetWorkflowInstance(workflowInstanceId);
                }while (instance.UserStatus == "Wait for Submit");
            }
            TempData["Message"] = "Successfully Submitted For Approval!";


            return(RedirectToAction("Details", new { id = id, SPHostUrl = spHostUrl }));
        }
Exemplo n.º 6
0
        public ActionResult Details(int id)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                var service = new PartSuppliersService(clientContext);
                var item    = service.GetItem(id);
                if (item == null)
                {
                    return(HttpNotFound());
                }

                var workflowSubscription = service.GetWorkflowSubscription("Approve Suppliers");

                ViewBag.AppWebUrl            = spContext.SPAppWebUrl.ToString();
                ViewBag.WorkflowSubscription = workflowSubscription;
                ViewBag.WorkflowInstance     = service.GetItemWorkflowInstance(workflowSubscription.Id, id);
                ViewBag.ApprovalTask         = service.GetApprovalTaskForCurrentUser(id);

                return(View(item));
            }
        }