コード例 #1
0
        public async Task <TextPostRes> CreateTextPostAsync(long createdByUserId, CreateTextPostReq req)
        {
            var user = UnitOfWork.AppUsers.GetById(createdByUserId);

            if (user == null)
            {
                throw new BusinnessException("Invalid user id: " + createdByUserId);
            }

            var textPost = Mapper.Map <TextPost>(req); // map to database model

            textPost.CreatedByUserId   = user.Id;
            textPost.CreatedByUserName = user.FirstName + " " + user.LastName;

            var res = await UnitOfWork.TextPostRepo.InsertAsync(textPost);

            return(Mapper.Map <TextPostRes>(res)); // map to DTO
        }
コード例 #2
0
        public async Task <IHttpActionResult> TextPost(CreateTextPostReq req)
        {
            var userId = GetUserIdFromContext();

            return(Ok(await _postsService.CreateTextPostAsync(userId, req)));
        }