コード例 #1
0
        public IHttpActionResult PostArticleStructureTemplate(ArticleStructureTemplateDto articleStructureTemplateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!IsUserSiteAdmin() && !IsUserLeadClinician())
            {
                return(Unauthorized());
            }

            var articleStructureTemplate = new ArticleStructureTemplate()
            {
                Id        = articleStructureTemplateDto.Id,
                Structure = JsonConvert.SerializeObject(articleStructureTemplateDto.Structure),
                Title     = articleStructureTemplateDto.Title
            };

            _db.ArticleStructureTemplates.Add(articleStructureTemplate);

            _db.Logs.Add(
                _logHelper.CreateArticleStructureTemplateApiControllerLog(
                    LogHelper.LogType.Create,
                    "ArticleStructureTemplateApiController.PostArticleStructureTemplate",
                    "api/article/template/post/",
                    articleStructureTemplate,
                    User.GetUsernameWithoutDomain()
                    )
                );

            _db.SaveChanges();

            return(Ok(articleStructureTemplateDto));
        }
コード例 #2
0
        public IHttpActionResult PutArticleStructureTemplate(int id, ArticleStructureTemplateDto articleStructureTemplateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!IsUserSiteAdmin() && !IsUserLeadClinician())
            {
                return(Unauthorized());
            }

            if (id != articleStructureTemplateDto.Id)
            {
                return(BadRequest());
            }

            var articleStructureTemplate = new ArticleStructureTemplate()
            {
                Id        = articleStructureTemplateDto.Id,
                Structure = JsonConvert.SerializeObject(articleStructureTemplateDto.Structure),
                Title     = articleStructureTemplateDto.Title
            };

            _db.Logs.Add(
                _logHelper.CreateArticleStructureTemplateApiControllerLog(
                    LogHelper.LogType.Update,
                    "ArticleStructureTemplateApiController.PutArticleStructureTemplate",
                    $"api/article/template/put/{id}",
                    articleStructureTemplate,
                    User.GetUsernameWithoutDomain()
                    )
                );

            _db.MarkArticleStructureTemplateAsModified(articleStructureTemplate);

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleStructureTemplateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult GetArticleStructureTemplate(int id)
        {
            var articleStructureTemplate = _db.ArticleStructureTemplates.Find(id);

            if (articleStructureTemplate == null)
            {
                return(NotFound());
            }

            var articleStructureTemplateDto = new ArticleStructureTemplateDto()
            {
                Id        = articleStructureTemplate.Id,
                Structure = JsonConvert.DeserializeObject(articleStructureTemplate.Structure),
                Title     = articleStructureTemplate.Title
            };

            return(Ok(articleStructureTemplateDto));
        }
コード例 #4
0
        public Log CreateArticleStructureTemplateApiControllerLog(LogType notificationType, string method, string requestUri, ArticleStructureTemplate articleStructureTemplate, string samAccountName)
        {
            object action;
            var    details = new ArticleStructureTemplateDto()
            {
                Id        = articleStructureTemplate.Id,
                Title     = articleStructureTemplate.Title,
                Structure = articleStructureTemplate.Structure
            };

            switch (notificationType)
            {
            case LogType.Create:
                action = new
                {
                    Action  = $"Article template created {articleStructureTemplate.Title}.",
                    Details = details
                };
                break;

            case LogType.Update:
                action = new
                {
                    Action  = $"Article template updated {articleStructureTemplate.Title}.",
                    Details = details
                };
                break;

            case LogType.Delete:
                action = new
                {
                    Action  = $"Article template delete {articleStructureTemplate.Title}.",
                    Details = details
                };
                break;

            default:
                action = null;
                break;
            }

            return(action != null?CreateLog(samAccountName, method, requestUri, action) : null);
        }