Esempio n. 1
0
        /// <summary>
        /// Add's new model to the database by the name of the model
        /// </summary>
        /// <param name="modelId"></param>
        /// <returns></returns>

        public async Task <bool> AddNewModel(string modelId, string usersEmail, string modelFriendlyName)
        {
            try
            {
                if (string.IsNullOrEmpty(modelId) || string.IsNullOrEmpty(usersEmail))
                {
                    return(false);
                }

                // Disallow creation of model if user has exceeded maximum allowed models
                if (this.MaxAllowedModels(usersEmail).Result)
                {
                    return(false);
                }

                await _context.UploadedModels.AddAsync(new UsersUploadedModels()
                {
                    EmailAddress        = usersEmail,
                    ModelId             = modelId,
                    ModelUploadDateTime = DateTime.UtcNow,
                    UploadedModelCount  = this.ReturnUserModels(usersEmail).Result.Count,
                    ModelFriendlyName   = modelFriendlyName
                });

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task <bool> AddUser(string emailAddress)
        {
            try
            {
                if (string.IsNullOrEmpty(emailAddress))
                {
                    return(false);
                }

                if (this.CheckForExistingUser(emailAddress).Result)
                {
                    return(false);
                }

                await _context.Users.AddAsync(new AuthenticatedUserModel()
                {
                    EmailAddress = emailAddress,
                    LastLogin    = DateTime.UtcNow,
                    ApiKey       = $"FL.{Guid.NewGuid()}"
                });

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }