示例#1
0
        public async Task <IActionResult> AddDocument([FromBody] DocumentNewDto model)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _identityService.GetCurrentPersonIdentityAsync();

                if (currentUser == null)
                {
                    return(BadRequest(new MessageDto()
                    {
                        Success = true, Message = "Invalid user"
                    }));
                }

                var document = new Entities.Document()
                {
                    OwnerId      = currentUser.Id,
                    Subject      = model.Subject,
                    Title        = model.Title,
                    CreatedOnUtc = DateTime.Now
                };
                var result = await _documentService.InsertDocument(document);

                if (result.Success)
                {
                    await _documentService.AssignClientToEditDocument(currentUser.Id, currentUser.Id, document.Id);

                    await _documentService.AssignClientToViewDocument(currentUser.Id, currentUser.Id, document.Id);

                    return(new OkObjectResult(result));
                }
                else
                {
                    return(BadRequest(result));
                }
            }
            return(BadRequest(new MessageDto()
            {
                Success = false, Message = "Invalid document"
            }));
        }