public ActionResult Create()
        {
            var viewModel = new EditViewModel
            {
                Id = string.Empty,
                Name = string.Empty,
                LabelType = LabelType.User,
                LabelListVisibilityType = (int)LabelListVisibilityType.Show,
                MessageListVisibilityType = (int)MessageListVisibilityType.Show
            };
            SetEditSelectLists(viewModel);

            return View(viewModel);
        }
        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");
        }
        public async Task<ActionResult> Edit(string id)
        {
            var labelsManager = GetLabelsManager();
            LabelInfo label;
            try
            {
                label = await labelsManager.GetAsync(id);
            }
            catch (GoogleApiException ex)
            {
                if (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound)
                    return HttpNotFound(string.Format("Label id {0} does not exist.", id));
                else
                    throw;
            }

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

            var viewModel = new EditViewModel
            {
                Id = label.Id,
                Name = label.Name,
                LabelType = label.LabelType,
                LabelListVisibilityType = (int)label.LabelListVisibilityType,
                MessageListVisibilityType = (int)label.MessageListVisibilityType
            };
            SetEditSelectLists(viewModel);

            return View(viewModel);
        }        
        private void SetEditSelectLists(EditViewModel viewModel)
        {
            var labelListVisibilityTypes = new SelectList(new[]
            {
                new { ID = (int)LabelListVisibilityType.Show, Name = "Show" },
                new { ID = (int)LabelListVisibilityType.Hide, Name = "Hide" },
                new { ID = (int)LabelListVisibilityType.ShowIfUnread, Name = "Show if unread" }                
            }, "ID", "Name");

            var messageListVisibilityTypes = new SelectList(new[]
            {
                new { ID = (int)MessageListVisibilityType.Show, Name = "Show" },
                new { ID = (int)MessageListVisibilityType.Hide, Name = "Hide" }
            }, "ID", "Name");

            viewModel.LabelListVisibilityTypes = labelListVisibilityTypes;
            viewModel.MessageListVisibilityTypes = messageListVisibilityTypes;
        }
        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");
        }