コード例 #1
0
        public static Label ToLabel(this LabelInfo labelInfo)
        {
            System.Diagnostics.Debug.Assert(labelInfo != null);

            return(new Label
            {
                Id = labelInfo.Id,
                Name = labelInfo.Name,
                Type = FromLabelType(labelInfo.LabelType),
                LabelListVisibility = FromLabelListVisibilityType(labelInfo.LabelListVisibilityType),
                MessageListVisibility = FromMessageListVisibilityType(labelInfo.MessageListVisibilityType)
            });
        }
コード例 #2
0
        public async Task<LabelInfo> UpdateAsync(LabelInfo labelInfo)
        {
            if (labelInfo == null)
                throw new ArgumentNullException("labelInfo");

            var body = labelInfo.ToLabel();

            var gmailService = await _gmailApiComponent.GetGmailService(_userId, _userName);
            var result = await await _gmailApiComponent.ExecuteBackoffAsync(() => gmailService.Users.Labels.Update(body, "me", labelInfo.Id).ExecuteAsync().ConfigureAwait(false))
                .ConfigureAwait(false);

            return result.ToLabelInfo();
        }
コード例 #3
0
        public async Task<ActionResult> Create(EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                SetEditSelectLists(viewModel);
                return View(viewModel);
            }

            var labelInfo = new LabelInfo
            {
                Id = viewModel.Id,
                Name = viewModel.Name,
                LabelType = viewModel.LabelType,
                LabelListVisibilityType = (LabelListVisibilityType)viewModel.LabelListVisibilityType,
                MessageListVisibilityType = (MessageListVisibilityType)viewModel.MessageListVisibilityType
            };

            var labelsManager = GetLabelsManager();
            await labelsManager.CreateAsync(labelInfo);

            await Task.Run(() => new TelemetryClient().TrackEvent("CreateLabel"));

            return RedirectToAction("Index");
        }
コード例 #4
0
        public async Task<ActionResult> Edit(EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                SetEditSelectLists(viewModel);
                return View(viewModel);
            }

            var labelsManager = GetLabelsManager();
            LabelInfo label;
            try
            {
                label = await labelsManager.GetAsync(viewModel.Id);
            }
            catch (GoogleApiException ex)
            {
                if (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound)
                    return HttpNotFound(string.Format("Label id {0} does not exist.", viewModel.Id));
                else
                    throw;
            }

            if (!label.IsUserType)
                return HttpNotFound();

            var labelInfo = new LabelInfo
            {
                Id = viewModel.Id,
                Name = viewModel.Name,
                LabelType = viewModel.LabelType,
                LabelListVisibilityType = (LabelListVisibilityType)viewModel.LabelListVisibilityType,
                MessageListVisibilityType = (MessageListVisibilityType)viewModel.MessageListVisibilityType
            };

            await labelsManager.UpdateAsync(labelInfo);

            await Task.Run(() => new TelemetryClient().TrackEvent("EditLabel"));

            return RedirectToAction("Index");
        }