Exemple #1
0
        public IHttpActionResult Post([FromUri] string id, [FromBody] VerifyLicenseRequest request)
        {
            try
            {
                var license = _service.Get(id);

                #region Validation
                if (license == null)
                {
                    return(BadRequestWithError(ApiErrorEnum.LicenseNotFound,
                                               string.Format("No such license with the given Id {0}.", id)));
                }

                if (!license.Enabled)
                {
                    return(BadRequestWithError(ApiErrorEnum.LicenseNotEnabled,
                                               string.Format("LIcense with Id {0} has not been enabled.", id)));
                }

                if (request == null ||
                    string.IsNullOrEmpty(request.ActivationKey))
                {
                    return(BadRequestWithError(ApiErrorEnum.NoActivationKey, "No activation key supplied."));
                }

                if (!_service.CheckOrActivate(license, request.ActivationKey, request.ComputerName))
                {
                    return(BadRequestWithError(ApiErrorEnum.LicenseActivationFailed, "Cannot activate license."));
                }
                #endregion

                return(Ok(new LicenseMessage(license)));
            }
            catch (Exception ex)
            {
                _logger.Log(NLog.LogLevel.Error, ex);

                return(BadRequestWithError(ApiErrorEnum.GeneralError));
            }
        }