Exemple #1
0
        public async Task <IHttpActionResult> Save(LogModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Name))
                {
                    return(BadRequest(ResponseMessages.LogNameRequired.ToDesc()));
                }

                if (await _logRepository.LogAlreadyExistsAsync(model.Name, CurrentUserId))
                {
                    return(BadRequest(ResponseMessages.LogNameDuplicate.ToDesc()));
                }

                var user = await _userRepository.GetById(CurrentUserId);

                if (user == null)
                {
                    return(BadRequest(ResponseMessages.UserNotFound.ToDesc()));
                }
                var x = model.ToNewEntity();

                x.UserId = user._id.ToString();
                await _logRepository.AddAsync(x);

                var notification = CreateNotification(x, model);
                await _notificationRepository.CreateOrUpdate(notification);

                if (model.IsDailyDigestEmail)
                {
                    _jobRunner.CreateDigestEmailJobIfNotExists(notification);
                }

                return(Ok(ResponseMessages.LogAdded.ToDesc()));
            }
            catch (Exception ex)
            {
                LogVerbose(ex);
            }
            return(InternalServerError());
        }