/// <summary> /// try to create a user if it goes through return a true otherwise return a flase /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <int> CreateUser(User user) { try { var newUser = DbEntityConverter.ToUserEntity(user); // convert await _context.AddAsync(newUser); await _context.SaveChangesAsync(); return(newUser.Id); } catch { return(-1); } }
public async Task <int> CreateAsync(Comment comment) { try { comment.NullCheck(nameof(comment)); var entity = DbEntityConverter.ToCommentEntity(comment); await _context.CommentEntities.AddAsync(entity); await _context.SaveChangesAsync(); return(entity.Id); } catch { return(-1); } }
public async Task <int> CreatePostAsync(Post post) { try { var newPost = DbEntityConverter.ToPostEntity(post); await _context.AddAsync(newPost); await _context.SaveChangesAsync(); return(newPost.Id); } catch { return(-1); } }