public static Model.RegisteredApplication FromDataModel(Core.Data.RegisteredApplication source, bool includeSensitiveInfo = false)
        {
            if (source == null)
            {
                return(null);
            }

            var a = new Model.RegisteredApplication
            {
                ID              = source.Id,
                Title           = source.Title,
                Description     = source.Description,
                WebsiteURL      = source.WebsiteUrl,
                IsEnabled       = source.IsEnabled,
                IsWriteEnabled  = source.IsWriteEnabled,
                IsPublicListing = source.IsPublicListing,
                DateCreated     = source.DateCreated
            };

            if (includeSensitiveInfo)
            {
                a.AppID = source.AppId;
                a.DateAPIKeyLastUsed = source.DateApikeyLastUsed;
                //DateAPIKeyUpdated  = source.DateAPIKeyUpdated
                a.PrimaryAPIKey    = source.PrimaryApikey;
                a.DeprecatedAPIKey = source.DeprecatedApikey;
                a.UserID           = source.UserId;
            }

            return(a);
        }
        public RegisteredApplication UpdateRegisteredApplication(RegisteredApplication update, int?userId)
        {
            Core.Data.RegisteredApplication item = new Core.Data.RegisteredApplication();

            if (update.ID > 0)
            {
                item = dataModel.RegisteredApplications.FirstOrDefault(a => a.Id == update.ID && (userId == null || (userId != null && update.UserID == userId)));
            }
            else
            {
                item.DateCreated   = DateTime.UtcNow;
                item.IsEnabled     = true;
                item.PrimaryApikey = Guid.NewGuid().ToString().ToLower();
                item.AppId         = Guid.NewGuid().ToString().ToLower();
                item.SharedSecret  = Guid.NewGuid().ToString().ToLower();
                item.UserId        = (int)userId;
            }

            item.Title           = update.Title;
            item.WebsiteUrl      = update.WebsiteURL;
            item.Description     = update.Description;
            item.IsPublicListing = update.IsPublicListing;

            if (userId == null)
            {
                item.IsEnabled      = update.IsEnabled;
                item.IsWriteEnabled = update.IsWriteEnabled;
            }

            if (item.Id == 0)
            {
                dataModel.RegisteredApplications.Add(item);
            }

            dataModel.SaveChanges();

            return(OCM.API.Common.Model.Extensions.RegisteredApplication.FromDataModel(item));
        }