Exemple #1
0
        public Application GetApplication(string applicationClientId)
        {
            string[] split = applicationClientId.DelimitSplit(":");
            if (split.Length != 2)
            {
                throw new ArgumentException("The specified applicationClientId is not valid: {0}"._Format(applicationClientId));
            }

            return(Application.OneWhere(c => c.Name == split[0], Database));
        }
Exemple #2
0
        public static ApplicationCreateResult CreateApplication(IHttpContext context, IUserResolver userResolver, string applicationName, Database database = null)
        {
            ApplicationCreateResult result = new ApplicationCreateResult();

            try
            {
                Application app = Application.OneWhere(c => c.Name == applicationName, database);
                if (app != null)
                {
                    result.Status = ApplicationCreateStatus.NameInUse;
                }
                else
                {
                    string createdBy = userResolver.GetUser(context);
                    if (string.IsNullOrEmpty(createdBy))
                    {
                        createdBy = userResolver.GetCurrentUser();
                        if (string.IsNullOrEmpty(createdBy))
                        {
                            throw new UnableToResolveUserException(userResolver);
                        }
                    }

                    app = new Application
                    {
                        Name = applicationName
                    };
                    app.Save(database);
                    AddKey(app, userResolver, context);

                    result.Application = app;
                    result.Status      = ApplicationCreateStatus.Success;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Status  = ApplicationCreateStatus.Error;
            }

            return(result);
        }