public async Task <IHttpActionResult> LogAsync(LogCreateModel logCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            LogCreateDto logCreateDto = logCreateModel.ToLogCreateDto();

            try
            {
                int id = await _logService.AddLogAsync(logCreateDto, User.Identity.Name);

                return(Ok(new LogCreationResultModel()
                {
                    success = id > 0
                }));
            }
            catch (Exception)
            {
                return(Ok(new LogCreationResultModel()
                {
                    success = false
                }));
            }
        }
 public static LogCreateDto ToLogCreateDto(this LogCreateModel logCreateModel)
 {
     return(ObjectMapperManager
            .DefaultInstance
            .GetMapper <LogCreateModel, LogCreateDto>()
            .Map(logCreateModel));
 }
        public async Task WhenLoggingWithBadApplicationIdThenErrorShouldBeRaised()
        {
            using (IDependencyResolver resolver = DependencyResolverFactory.CreateDependencyResolver())
            {
                LoggerController controller = new LoggerController(resolver.Resolve <IApplicationService>(),
                                                                   resolver.Resolve <ILogService>());

                LogCreateModel logCreateModel = new LogCreateModel()
                {
                    ApplicationId = 0,  // bad application_id
                    Logger        = "logger",
                    Level         = "level",
                    Message       = "message"
                };

                var result = await controller.LogAsync(logCreateModel) as OkNegotiatedContentResult <LogCreationResultModel>;

                Assert.AreEqual(result.Content.success, false);
            }
        }