public async Task <Response <ComunityEntity> > Update(string userId, ComunityEntity entity) { var responce = new Response <ComunityEntity>(); var isExist = await _context.Comunities.AnyAsync(x => x == entity); if (!isExist) { responce.Error = new Error("This following not exist"); return(responce); } if (userId != entity.FollowingFromId || userId != entity.FollowingToId) { responce.Error = new Error("You don`t have permisions to update this state"); return(responce); } switch (entity.Status) { case FollowingStatus.Accepted: _context.Comunities.Update(entity); break; case FollowingStatus.Rejected: _context.Comunities.Remove(entity); break; } await _context.SaveChangesAsync(); responce.Data = entity; return(responce); }
public async Task <Response <OperationResult> > Create(string userId, FollowingRequest model) { var responce = new Response <OperationResult>(); var entity = new ComunityEntity(userId, model); await _context.Comunities.AddAsync(entity); await _context.SaveChangesAsync(); responce.Data = OperationResult.Success; return(responce); }