Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostAsync(int projectId, [FromBody] MailMessageItemDto model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var project = await _projectManager.FindByIdAsync(projectId, cancellationToken);

            await ApiSecurity.AuthorizeAsync(project, AccessPermission.CanEdit, cancellationToken);

            var mailMessage = new MailMessageItem {
                Subject = model.Subject, Body = model.Body
            };
            var validationResult = await _projectManager.AddMailMessageAsync(project, mailMessage, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }
            return(CreatedAtRoute("Project.Mails.GetById", new RouteValueDictionary {
                { "id", mailMessage.Id }
            }, mailMessage));
        }