Exemple #1
0
        internal EntityResult CreateLegal(int topicId, int attachmentId, int userId, LegalFormModel legalModel)
        {
            try
            {
                DbContext.TopicAttatchments.Include(at => at.Legal).Single(at => at.Id == attachmentId);
            }
            catch (InvalidOperationException)
            {
                return(EntityResult.Error("Unknown Attachment"));
            }
            // TODO already exitst´s
            try
            {
                Legal legal = new Legal(attachmentId, legalModel);

                DbContext.Add(legal);
                DbContext.SaveChanges();

                return(EntityResult.Successfull());
            }
            catch (Exception e)
            {
                return(EntityResult.Error(e.Message));
            }
        }
Exemple #2
0
 public Legal(int attatchmentId, LegalFormModel legalModel)
 {
     TopicAttatchmentId = attatchmentId;
     PublishedDate      = legalModel.PublishedDate;
     PublicationType    = legalModel.PublicationType;
     Author             = legalModel.Author;
     Name          = legalModel.Name;
     Description   = legalModel.Description;
     PublishedDate = legalModel.PublishedDate;
     Source        = legalModel.Source;
 }
        public IActionResult PostLegal([FromRoute] int topicId, [FromRoute] int attachmentId, [FromBody] LegalFormModel legalModel)
        {
            if (!_topicPermissions.IsAssociatedTo(User.Identity.GetUserId(), topicId))
            {
                return(Forbidden());
            }

            if (ModelState.IsValid)
            {
                var result = _attachmentsManager.CreateLegal(topicId, attachmentId, User.Identity.GetUserId(), legalModel);
                if (result.Success)
                {
                    return(Ok(result));
                }
                return(InternalServerError(result));
            }

            return(BadRequest(ModelState));
        }