Exemple #1
0
        public async Task <Post> SavePost(PostForUpload post)
        {
            var item = await _context.Post.AddAsync(new Post
            {
                UserId   = post.UserId,
                Title    = post.Title,
                Content  = post.Content,
                Tags     = post.Tags,
                Status   = post.Status,
                Price    = post.Price,
                Address  = post.Address,
                UpTime   = DateTime.UtcNow,
                EditTime = DateTime.UtcNow
            });

            await _context.SaveChangesAsync();

            if (post.Medias != null)
            {
                foreach (var media in post.Medias)
                {
                    await _context.MediaLink.AddAsync(new MediaLink
                    {
                        MediaId = Guid.NewGuid().ToString(),
                        PostId  = item.Entity.PostId,
                        ResType = media.ResType.ToString(),
                        ResUri  = media.ResUri.RemoveServerAddress(_imageServer)
                    });
                }
            }
            await _context.SaveChangesAsync();

            return(item.Entity);
        }
Exemple #2
0
        public async Task <User> Register(UserSmall user)
        {
            // 新增用户
            var addedUser = await _context.User.AddAsync(new User
            {
                Username     = user.Username.ToLower(),
                Nickname     = user.Username,
                PasswordHash = user.Password.GetMd5Hash(),
                UserGroup    = 9
            });

            await _context.SaveChangesAsync();

            return(addedUser.Entity);
        }
        public async Task <UploadedImage> SaveImage(string imageHash, string fileName, DateTime dateTime)
        {
            var image = await _context.UploadedImage.AddAsync(new UploadedImage
            {
                Hash       = imageHash,
                FileName   = fileName,
                UploadTime = dateTime
            });

            await _context.SaveChangesAsync();

            return(image.Entity);
        }
        public async Task <Collection> SaveCollection(int userId, int postId, int privacy)
        {
            var item = await _context.Collection.AddAsync(new Collection
            {
                UserId         = userId,
                PostId         = postId,
                Privacy        = privacy,
                CollectionTime = DateTime.UtcNow
            });

            await _context.SaveChangesAsync();

            return(item.Entity);
        }
Exemple #5
0
        public async Task <User> UpdateUser(string username, UserLarge user)
        {
            var item = await GetUser(username);

            if (item == null)
            {
                return(null);
            }
            item.Nickname  = user.Nickname;
            item.Phone     = user.Phone;
            item.BirthDate = user.BirthDate;
            item.Sex       = user.Sex;
            item.Address   = user.Address;
            item.ImageUrl  = user.ImageUrl.RemoveServerAddress(_imageServer);
            await _context.SaveChangesAsync();

            return(item);
        }