public async Task <ActionResult> SelectProject(SelectProjectViewModel model)
        {
            try
            {
                if (model.ProjectId.HasValue)
                {
                    DateTime?endAt = null;

                    if (model.ManualInput.HasValue && model.ManualInput.Value)
                    {
                        string token = GetToken();

                        if ((await _userProvider.GetUserAsync(token)) != null)
                        {
                            var subscriptions = await _subscriptionProvider.GetSubscriptionsAsync(token);

                            // The user does not have to be logged in and projects may not always be owned by the user. Getting subscription EndAt date might not be possible. Hence the allowed null outcome.
                            endAt = subscriptions.FirstOrDefault(s => s.Projects.Any(p => p.Id == AppSettingProvider.ProjectId))?.CurrentPlan?.EndAt;
                        }
                    }

                    try
                    {
                        _selfConfigManager.SetProjectIdAndExpirationAsync(model.ProjectId.Value, endAt);
                    }
                    catch (ConfigurationErrorsException ex)
                    {
                        return(View("Error", new MessageModel {
                            Caption = CAPTION_CONFIGURATION_WRITE_ERROR, Message = ex.Message, MessageType = MessageType.Error
                        }));
                    }

                    return(RedirectHelpers.GetHomeRedirectResult(new MessageModel {
                        Caption = null, Message = $"You've configured your app with a project ID \"{model.ProjectId}\".", MessageType = MessageType.Info
                    }));
                }
                else
                {
                    try
                    {
                        _selfConfigManager.SetSharedProjectIdAsync();

                        return(View("Error", new MessageModel {
                            Caption = "Missing project ID", Message = "The submitted project ID was an empty GUID. The app was configured with the shared project ID instead. You may wish to reconfigure the project ID in your environment settings (Azure application settings, web.config, etc.).", MessageType = MessageType.Error
                        }));
                    }
                    catch (ConfigurationErrorsException ex)
                    {
                        return(View("Error", new MessageModel {
                            Caption = CAPTION_CONFIGURATION_WRITE_ERROR, Message = ex.Message, MessageType = MessageType.Error
                        }));
                    }
                }
            }
            catch (JsonSerializationException ex)
            {
                return(GetDeserializationErrorResult(ex));
            }
        }
Example #2
0
        public Redmine()
        {
            _selectProjectViewModel = new SelectProjectViewModel();

            UpdateRedmineUser();
        }