public async Task <ActionResult> Edit(string id)
        {
            InviteTemplate template;

            if (id == null)
            {
                ViewBag.Operation = "New";
                template          = new InviteTemplate();
            }
            else
            {
                ViewBag.Operation = "Edit";
                template          = await TemplateUtilities.GetTemplate(id);
            }
            return(View(template));
        }
示例#2
0
        //private BulkInviteResults SubmitToGraphBatch(GraphBatch batch, BulkInviteSubmission submission)
        //{
        //    //** NOTE: this method was last tested against the beta API, circa Q3 CY17 **
        //    var res = new BulkInviteResults();
        //    var batchEndPoint = string.Format("{0}/beta/$batch", Settings.GraphResource);
        //    var serverResponse = CallGraph(batchEndPoint, batch, false, null, _userId);

        //    if (serverResponse.Successful)
        //    {
        //        res.InvitationResults = JsonConvert.DeserializeObject<GraphBatchResponse>(serverResponse.ResponseContent);
        //        if (submission.GroupList.Length > 0)
        //        {
        //            foreach (var item in res.InvitationResults.Responses)
        //            {
        //                var groupsAdded = AddUserToGroup(item.Body.InvitedUser.Id, submission.GroupList.ToList());
        //                if (!groupsAdded.Success)
        //                {
        //                    var resErrors = string.Join(", ", groupsAdded.Responses.Where(r => !r.Successful).Select(r => r.Message));
        //                    res.ErrorMessage += string.Format("\n\rOne or more groups failed while assigning to user \"{0}\" ({1})", item.Body.InvitedUserEmailAddress, resErrors);
        //                }
        //            }
        //        }
        //    }
        //    else
        //    {
        //        res.ErrorMessage = serverResponse.Message;
        //    }
        //    return res;
        //}

        private async Task <BulkInviteResults> SubmitLocally(GraphBatch batch, BulkInviteSubmission submission)
        {
            var res = new BulkInviteResults(submission.Id);

            GraphInvitation itemRes;
            var             mailTemplate = await TemplateUtilities.GetTemplate(submission.InviteTemplateId);

            try
            {
                foreach (var item in batch.Requests)
                {
                    itemRes = await SendGraphInvitationAsync(item.Body, submission.GroupList.ToList(), null, mailTemplate, _accessToken);

                    if (itemRes.Status != "Error")
                    {
                        submission.ItemsProcessed += 1;
                        submission = await BulkInviteSubmission.UpdateItem(submission);
                    }
                    item.Request.Status = itemRes.Status;
                    await GuestRequestRules.UpdateAsync(item.Request);

                    res.InvitationResults.Responses.Add(new BulkResponse
                    {
                        Status = itemRes.Status,
                        Body   = itemRes,
                        Id     = itemRes.id
                    });
                }

                await BulkInviteResults.AddItem(res);

                return(res);
            }
            catch (Exception ex)
            {
                res.ErrorMessage = ex.Message;
                await BulkInviteResults.AddItem(res);

                return(res);
            }
        }